layui.define(['admin', 'table', 'form', 'upload', 'laydate'], function(exports) {
	var table = layui.table,
		form = layui.form,
		admin = layui.admin,
		view = layui.view,
		upload = layui.upload,
		laydate = layui.laydate,
		element = layui.element,
		$ = layui.$,
		curr_tab = 0 //当前tab索引
		,
		cols = [
			[{
					type: 'checkbox'
				},
				{
					width: 110,
					templet: '#LAY-good-list-table-img',
					title: '商品',
					field: 'image'
				}, {
					width: 200,
					field: 'title',
					title: '书名'
				}, {
					width: 150,
					field: 'new_book_price',
					title: '价格',
					templet: '#LAY-good-list-table-price'
				}, {
					width: 100,
					field: 'total_stock',
					title: '库存',
					sort: true,
					templet: '#LAY-good-list-table-stock'
				}, {
					width: 100,
					field: 'sales_total',
					title: '总销量',
					sort: true
				}, {
					width: 100,
					field: 'category_pid_title',
					title: '所属分类'
				}, {
					width: 136,
					title: 'ISBN',
//					templet: '#LAY-good-list-modules',
					field: 'isbn'
				}, {
					width: 100,
					field: 'is_recycle',
					title: '是否回收',
					templet: '#LAY-good-list-recycle',
				}, {
					width: 220,
					align: 'center',
					fixed: 'right',
					title: '操作',
					toolbar: '#LAY-good-list-table-edit'
				}
			]
		];
	table.set({
		headers: { //通过 request 头传递
			'access-token': layui.data('layuiAdmin').access_token
		}
	});
	form.render(null, 'goods-list-form');
	table.render({
		elem: '#LAY-good-list-status6',
		url: 'https://bookshop.dingdangtoy.com/api/admin/book/index?type=5',
		parseData: function(res) { //res 即为原始返回的数据
			return {
				"code": res.code, //解析接口状态
				"msg": res.message, //解析提示文本
				"count": res.data._meta.total_count, //解析数据长度
				"data": res.data.items //解析数据列表
			}
		},
		cols: cols,
		page: true
	});
	table.render({
		elem: '#LAY-good-list-status5',
		url: 'https://bookshop.dingdangtoy.com/api/admin/book/index?type=4',
		parseData: function(res) { //res 即为原始返回的数据
			return {
				"code": res.code, //解析接口状态
				"msg": res.message, //解析提示文本
				"count": res.data._meta.total_count, //解析数据长度
				"data": res.data.items //解析数据列表
			}
		},
		cols: cols,
		page: true
	});
	table.render({
		elem: '#LAY-good-list-status4',
		url: 'https://bookshop.dingdangtoy.com/api/admin/book/index?type=0',
		parseData: function(res) { //res 即为原始返回的数据
			return {
				"code": res.code, //解析接口状态
				"msg": res.message, //解析提示文本
				"count": res.data._meta.total_count, //解析数据长度
				"data": res.data.items //解析数据列表
			}
		},
		cols: cols,
		page: true
	});
	table.render({
		elem: '#LAY-good-list-status3',
		url: 'https://bookshop.dingdangtoy.com/api/admin/book/index?type=3',
		parseData: function(res) { //res 即为原始返回的数据
			return {
				"code": res.code, //解析接口状态
				"msg": res.message, //解析提示文本
				"count": res.data._meta.total_count, //解析数据长度
				"data": res.data.items //解析数据列表
			}
		},
		cols: cols,
		page: true
	});
	table.render({
		elem: '#LAY-good-list-status2',
		url: 'https://bookshop.dingdangtoy.com/api/admin/book/index?type=2',
		parseData: function(res) { //res 即为原始返回的数据
			return {
				"code": res.code, //解析接口状态
				"msg": res.message, //解析提示文本
				"count": res.data._meta.total_count, //解析数据长度
				"data": res.data.items //解析数据列表
			}
		},
		cols: cols,
		page: true
	});

	table.render({
		elem: '#LAY-good-list-status1',
		url: 'https://bookshop.dingdangtoy.com/api/admin/book/index?type=1',
		parseData: function(res) { //res 即为原始返回的数据
			return {
				"code": res.code, //解析接口状态
				"msg": res.message, //解析提示文本
				"count": res.data._meta.total_count, //解析数据长度
				"data": res.data.items //解析数据列表
			}
		},
		cols: cols,
		page: true
	});
	// 监听tab切换
	element.on('tab(goods-list-tabs)', function(data) {
		curr_tab = data.index
	});
	//监听工具条
	table.on('tool(LAY-good-list-status6)', function(obj) {
		var data = obj.data;
		if(obj.event === 'down') {
			$.ajax({
				type: "PUT",
				dataType: "json",
				url: "https://bookshop.dingdangtoy.com/api/admin/book/update_state",
				data: {
					state: '2',
					id: data.id
				},
				headers: { //通过 request 头传递
					'access-token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					layer.msg('操作成功');
					layui.table.reload('LAY-good-list-status1');
					layui.table.reload('LAY-good-list-status2');
					layui.table.reload('LAY-good-list-status3');
					layui.table.reload('LAY-good-list-status4');
					layui.table.reload('LAY-good-list-status5');
					layui.table.reload('LAY-good-list-status6');
				},
				error: function(msg) {
					console.log(msg)
				}
			});
		} else if(obj.event === 'up') {
			$.ajax({
				type: "PUT",
				dataType: "json",
				url: "https://bookshop.dingdangtoy.com/api/admin/book/update_state",
				data: {
					state: '1',
					id: data.id
				},
				headers: { //通过 request 头传递
					'access-token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					layer.msg('操作成功');
					layui.table.reload('LAY-good-list-status1');
					layui.table.reload('LAY-good-list-status2');
					layui.table.reload('LAY-good-list-status3');
					layui.table.reload('LAY-good-list-status4');
					layui.table.reload('LAY-good-list-status5');
					layui.table.reload('LAY-good-list-status6');
				},
				error: function(msg) {
					console.log(msg)
				}
			});
		} else if(obj.event === 'del') {
			layer.confirm('是否删除', function(index) {
				//        obj.del();
				//        layer.close(index);
				$.ajax({
					type: "DELETE",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/destroy",
					data: {
						id: data.id
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layer.msg('操作成功');
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.close(index); //执行关闭
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		} else if(obj.event === 'edit') {
			//         location.hash = '/goods/add-goods/index/book_id='+data.id;
			admin.popup({
				title: '编辑书籍',
				area: ['90%', '90%'],
				id: 'LAY-popup-shopping-add',
				success: function(layero, index) {
					view(this.id).render('goods/add-goods/addShopping', data).done(function() {
						form.render(null, 'layuiadmin-app-form-list');
						var content_author_intro = '';
						var content_desc = '';
						var content_catalog = '';
						// 富文本
				        var E = window.wangEditor
				        var editor2 = new E('#editor2')
				        editor2.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
				            content_catalog = html
				        }
						editor2.create()
				        var editor1 = new E('#editor1')
				        editor1.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
				            content_desc = html
				        }
						editor1.create()
				        var editor = new E('#editor')
				        editor.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
                           content_author_intro = html
				        }
				        editor.create()
						function toDecimal(num, n) {
							n = n ? parseInt(n) : 0;
							if(n <= 0) {
								return Math.round(num);
							}
							num = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); //四舍五入
							num = Number(num).toFixed(n); //补足位数
							return num;
						}
//						获取详情
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/book/show?id=" + data.id,
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
                                editor.txt.html(data.data.author_intro)
                                editor1.txt.html(data.data.desc)
                                editor2.txt.html(data.data.catalog)
                                content_desc = data.data.desc;
                                content_author_intro = data.data.author_intro;
								content_catalog = data.data.catalog;
								$('#new_book_stock').val(data.data.new_book_stock);
								$('#good_book_stock').val(data.data.good_book_stock);
								$('#medium_book_stock').val(data.data.medium_book_stock);
								$('#medium_book_stock2').val(data.data.medium_book_stock2);
								$('#medium_book_stock3').val(data.data.medium_book_stock3);
								$('#medium_book_stock4').val(data.data.medium_book_stock4);
								$('#medium_book_stock5').val(data.data.medium_book_stock5);
								$('#medium_book_stock6').val(data.data.medium_book_stock6);

								$('#new_book_price').val(data.data.new_book_price);
								$('#good_book_price').val(data.data.good_book_price);
								$('#medium_book_price').val(data.data.medium_book_price);
								$('#medium_book_price2').val(data.data.medium_book_price2);
								$('#medium_book_price3').val(data.data.medium_book_price3);
								$('#medium_book_price4').val(data.data.medium_book_price4);
								$('#medium_book_price5').val(data.data.medium_book_price5);
								$('#medium_book_price6').val(data.data.medium_book_price6);

								var price1 = parseFloat(data.data.old_price);
								var price2 = parseFloat(data.data.new_book_price);
								var price3 = parseFloat(data.data.good_book_price);
								$('#new_book_discount').text(toDecimal((price2/price1)*10,1));
								$('#good_book_discount').text(toDecimal((price3/price1)*10,1));
								$('#medium_book_discount').text(toDecimal((parseFloat(data.data.medium_book_price)/price1)*10,1));
								$('#medium_book_discount2').text(toDecimal((parseFloat(data.data.medium_book_price2)/price1)*10,1));
								$('#medium_book_discount3').text(toDecimal((parseFloat(data.data.medium_book_price3)/price1)*10,1));
								$('#medium_book_discount4').text(toDecimal((parseFloat(data.data.medium_book_price4)/price1)*10,1));
								$('#medium_book_discount5').text(toDecimal((parseFloat(data.data.medium_book_price5)/price1)*10,1));
								$('#medium_book_discount6').text(toDecimal((parseFloat(data.data.medium_book_price6)/price1)*10,1));
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						// 计算总价
						$('#allPrice').on('click', function(){
							var price1 = parseFloat($('#old_price').val());
							var price2 = parseFloat($('#new_book_price').val());
							var price3 = parseFloat($('#good_book_price').val());
							var pax = price3 + (price1*0.13);
		                    $('#new_book_price').val(toDecimal(pax,1));
							$('#medium_book_price').val(toDecimal(price3*0.85,1));
							$('#medium_book_price2').val(toDecimal(price3*0.75,1));
							$('#medium_book_price3').val(toDecimal(price3*0.7,1));
							$('#medium_book_price4').val(toDecimal(price3*0.8,1));
							$('#medium_book_price5').val(toDecimal(price3*0.75,1));
							$('#medium_book_price6').val(toDecimal(price3*0.7,1));
							$('#new_book_discount').text(toDecimal((parseFloat($('#new_book_price').val())/price1)*10,1));
							$('#good_book_discount').text(toDecimal((price3/price1)*10,1));
							$('#medium_book_discount').text(toDecimal((parseFloat($('#medium_book_price').val())/price1)*10,1));
							$('#medium_book_discount2').text(toDecimal((parseFloat($('#medium_book_price2').val())/price1)*10,1));
							$('#medium_book_discount3').text(toDecimal((parseFloat($('#medium_book_price3').val())/price1)*10,1));
							$('#medium_book_discount4').text(toDecimal((parseFloat($('#medium_book_price4').val())/price1)*10,1));
							$('#medium_book_discount5').text(toDecimal((parseFloat($('#medium_book_price5').val())/price1)*10,1));
							$('#medium_book_discount6').text(toDecimal((parseFloat($('#medium_book_price6').val())/price1)*10,1));
							return false;
						});
						//上传图片
						upload.render({
							elem: '#add-goods-upload-btn',
							url: 'https://bookshop.dingdangtoy.com/api/admin/image/store',
							accept: 'images',
							method: 'get',
							acceptMime: 'image/*',
							done: function(res) {
								console.log(res.data.url)
								$('#add-goods-upload-img').attr('src', res.data.url);
								$('#add-goods-upload-image').val(res.data.url)
								//$(this.item).prev("div").children("input").val(res.data.url)
							}
						});
						var flavors = data.category_ids.split(",");
						var v1 = '';
						var v2 = '';
						// 推荐位
						var omg = data.homepage_recommend_module_ids.split(",");
						if(data.old_price) {
							v1 = data.old_price;
						}
						// $('#new_book_price_discount').text((((parseFloat(data.new_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						// $('#good_book_price_discount').text((((parseFloat(data.good_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						// $('#medium_book_price_discount').text((((parseFloat(data.medium_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#recyle_price_discount').text((((parseFloat(data.recyle_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#old_price').keyup(function() {
							v1 = $(this).val();
						});
					    $('#new_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#new_book_discount').text('0');
					            	} else {
					            		$('#new_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#good_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#good_book_discount').text('0');
					            	} else {
					            		$('#good_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount').text('0');
					            	} else {
					            		$('#medium_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price2').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount2').text('0');
					            	} else {
					            		$('#medium_book_discount2').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price3').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount3').text('0');
					            	} else {
					            		$('#medium_book_discount3').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price4').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount4').text('0');
					            	} else {
					            		$('#medium_book_discount4').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price5').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount5').text('0');
					            	} else {
					            		$('#medium_book_discount5').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price6').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount6').text('0');
					            	} else {
					            		$('#medium_book_discount6').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
						$('#recyle_price').keyup(function() {
							v2 = $(this).val();
							if(v1 == '') { //验证第一个是否输入
								//alert('第一个文本框不为空');
								return false;
							} else {
								if(v2 == '') {
									//alert('第二个文本框不为空');
								} else {
									if(parseFloat(v2) / parseFloat(v1) == 1) {
										$('#recyle_price_discount').text('0');
									} else {
										$('#recyle_price_discount').text((((parseFloat(v2) / parseFloat(v1)) * 10)).toFixed(1));
									}

								}
							}
						});
						// 获取二级分类
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.category_pid,
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
								var _html1 = '';
								for(var i = 0; i < data.data.length; i++) {
									if(parseInt(data.data[i].id) !==0) {
										_html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
									}

								}
								$("#first-category-ids").append(_html1);
								for(var i = 0; i < flavors.length; i++) {
									$("input[name='category_ids']").each(function() {
										if($(this).val() == flavors[i]) {
											$(this).attr("checked", "checked");
										}
									})
								}
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						// 检测ISBN
						$('#detection').on('click', function() {
							//执行 Ajax 后重载
							$.ajax({
								type: "POST",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/book/check_isbn",
								data: {
									isbn: $('#isbn').val()
								},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									console.log(data)
									if(data.message) {
										$('#msg_info').text('库中已存在')
										$("#msg_info").css("color", "red");
									} else {
										$('#msg_info').text('库中不存在')
										$("#msg_info").css("color", "blue");
									}
								},
								error: function(msg) {
									console.log(msg)
								}
							});
							return false;
						});
						form.on('radio(category-pid)', function(data) {
							$("#first-category-ids").empty();
							// 获取二级分类
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.value,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									var _html1 = '';
									for(var i = 0; i < data.data.length; i++) {
										if(parseInt(data.data[i].id) !==0){
											_html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
										}

									}
									$("#first-category-ids").append(_html1);
									form.render();
								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
						// 获取推荐位
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/homepage_recommend_module/index",
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
								var _html = '';
								for(var i = 0; i < data.data.length; i++) {
									_html += '<input type="checkbox" name="homepage_recommend_module_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
								}     
								$("#first-homepage-recommend-module-ids").append(_html);
								for(var i = 0; i < omg.length; i++) {
									$("input[name='homepage_recommend_module_ids']").each(function() {
										if($(this).val() == omg[i]) {
											$(this).attr("checked", "checked");
										}
									})
								}
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						form.on('radio(category-pid)', function(data) {
							$("#first-category-ids").empty();
							// 获取二级分类
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.value,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									var _html1 = '';
									for(var i = 0; i < data.data.length; i++) {
										if(parseInt(data.data[i].id) !==0) {
											_html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
										}

									}
									$("#first-category-ids").append(_html1);
									form.render();
								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
						// 监听提交
						form.on('submit(layuiadmin-app-form-submit)', function(data) {
							var field = data.field; //获取提交的字段
							//提交 Ajax 成功后，关闭当前弹层并重载表格

							var arr = new Array();
							var arr_z = new Array();   
							$("input:checkbox[name='category_ids']:checked").each(function(i) {     
								arr[i] = $(this).val();  
							});
							$("input:checkbox[name='homepage_recommend_module_ids']:checked").each(function(s) {     
								arr_z[s] = $(this).val();  
							});   
							data.field.category_ids = arr.join(","); //将数组合并成字符串
							data.field.homepage_recommend_module_ids = arr_z.join(","); //将数组合并成字符串
							//执行 Ajax 后重载
							$.ajax({
								type: "PUT",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/book/update",
								data: {
									id: data.field.id,
									'category_pid': data.field.category_pid,
									'category_ids': data.field.category_ids,
									'title': data.field.title,
									'author': data.field.author,
									'sub_title': data.field.sub_title,
									'score': data.field.score,
									'image': data.field.image,
									'author_intro': content_author_intro,
									'publish_house': data.field.publish_house,
									'publish_time': data.field.publish_time,
									'publish_num': data.field.publish_num,
									'publish_translator': data.field.publish_translator,
									'publish_package': data.field.publish_package,
									'publish_paper': data.field.publish_paper,
									'publish_pages': data.field.publish_pages,
									'publish_open': data.field.publish_open,
									'isbn': data.field.isbn,
									'desc': content_desc,
									'catalog': content_catalog,
									'old_price': data.field.old_price,
									'new_book_price': data.field.new_book_price,
									'new_book_stock': data.field.new_book_stock,
									'good_book_price': data.field.good_book_price,
									'good_book_stock': data.field.good_book_stock,
									'medium_book_price': data.field.medium_book_price,
									'medium_book_stock': data.field.medium_book_stock,
									'medium_book_price2':data.field.medium_book_price2,
									'medium_book_stock2':data.field.medium_book_stock2,
									'medium_book_price3':data.field.medium_book_price3,
									'medium_book_stock3':data.field.medium_book_stock3,
									'medium_book_price4':data.field.medium_book_price4,
									'medium_book_stock4':data.field.medium_book_stock4,
									'medium_book_price5':data.field.medium_book_price5,
									'medium_book_stock5':data.field.medium_book_stock5,
									'medium_book_price6':data.field.medium_book_price6,
									'medium_book_stock6':data.field.medium_book_stock6,
									'is_recycle': data.field.is_recycle,
									'is_sult': data.field.is_sult,
									'recyle_price': data.field.recyle_price,
									'homepage_recommend_module_ids': data.field.homepage_recommend_module_ids
								},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									if(data.code == 0) {
										layer.msg('操作成功');
										layui.table.reload('LAY-good-list-status1');
										layui.table.reload('LAY-good-list-status2');
										layui.table.reload('LAY-good-list-status3');
										layui.table.reload('LAY-good-list-status4');
										layui.table.reload('LAY-good-list-status5');
					                    layui.table.reload('LAY-good-list-status6');
										// 执行关闭
										layer.close(index);
									} else {
										layer.msg(data.message);
									}

								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
					});
				}
			});

		} else if(obj.event === 'tips1') {
			admin.popup({
				title: '查看',
				area: ['400px', '350px'],
				id: 'LAY-popup-content-edit',
				success: function(layero, index) {
					view(this.id).render('goods/goods-list/price', data).done(function() {
						form.render(null, 'layuiadmin-form-tags1');
					});
				}
			});
		} else if(obj.event === 'tips2') {
			admin.popup({
				title: '查看',
				area: ['400px', '350px'],
				id: 'LAY-popup-content-edit1',
				success: function(layero, index) {
					view(this.id).render('goods/goods-list/stock', data).done(function() {
						form.render(null, 'layuiadmin-form-tags2');
					});
				}
			});
		} else if (obj.event === 'comment') {
		      admin.popup({
		        title: '编辑评论'
		        ,area: ['80%', '80%']
		        ,id: 'LAY-popup-comment-edit'
		        ,success: function(layero, index){
		          view(this.id).render('goods/goods-list/comment', data).done(function(){
		            form.render(null, 'layuiadmin-comment-list');
		            var book_id = data.id;
				    var cols = [[
				             {field:'user_avatar', title: '用户头像',templet: '#LAY-good-list-table-stock19',width:120,align: 'center'},
				             {field:'user_nickname', title: '用户'}
				            ,{field:'content', title: '评价内容'}
				            ,{field:'score', title: '评分'}
				            ,{width:178, align:'center', fixed: 'right',title: '操作', toolbar: '#LAY-good-list-table-edit1'}
				          ]];
					  table.set({
					    headers: { //通过 request 头传递
					      'access-token': layui.data('layuiAdmin').access_token
					    }
					  });
					  // 删除评论
					  table.on('tool(LAY-good-comment)', function(obj){
					  	var data = obj.data;
					  	if(obj.event === 'del'){
				        layer.confirm('是否删除', function(index){
				   	    $.ajax({
							    type: "DELETE",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/destroy",
							    data: {id:data.id},
							    headers: { //通过 request 头传递
					              'access-token': layui.data('layuiAdmin').access_token
					            },
								success: function(data){
								    layer.msg('操作成功');
								    layui.table.reload('LAY-good-comment'); //重载表格
						        layer.close(index); //执行关闭
								},
								error: function(msg){
								  console.log(msg)
								}
							});
				        });
					  	}
					  })
				    table.render({
				      elem: '#LAY-good-comment'
				      ,url: 'https://bookshop.dingdangtoy.com/api/admin/book_comment/index?book_id='+book_id
				      ,parseData: function(res){ //res 即为原始返回的数据
				        return {
				          "code": res.code, //解析接口状态
				          "msg": res.message, //解析提示文本
				          "data": res.data.items //解析数据列表
				        }
				      }
				      ,cols: cols
				      ,page: false
				    });
				    // 获取 图书信息
				    $.ajax({
						    type: "GET",
						    dataType: "json",
						    url: "https://bookshop.dingdangtoy.com/api/admin/book/show?id="+ book_id,
						    data: {},
						    headers: { //通过 request 头传递
					          'access-token': layui.data('layuiAdmin').access_token
					        },
							success: function(data){
								console.log(data.data)
								$('#title').text(data.data.title)
								$('#author').text(data.data.author)
								$('#title').text(data.data.title)
								$('#ISBN').text(data.data.isbn)
								$('#image').attr('src',data.data.image)
								form.render();
							},
							error: function(msg){
							  console.log(msg)
							}
						});
				    form.render(null, 'add-goods-form')
				    //监听提交
				    form.on('submit(formDemo)', function(data){
				    console.log(data)
				    layer.confirm('是否执行此操作？', function(index) {
				          //执行 Ajax 后重载
						    $.ajax({
							    type: "POST",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/store",
							    data: {
							    	book_id: book_id,
							    	user_nickname: data.field.user_nickname,
							    	user_id: data.field.user_id,
							    	user_avatar: data.field.user_avatar,
							    	score: data.field.score,
							    	content: data.field.content
							    },
							    headers: { //通过 request 头传递
						          'access-token': layui.data('layuiAdmin').access_token
						        },
								success: function(data){

				          table.reload('LAY-good-comment');
				          layer.msg('操作成功');
								},
								error: function(msg){
								  console.log(msg)
								}
							});
				        });
				    return false;
				    });
				    // 随机姓名
				    $('#random').on('click', function(){
				          //执行 Ajax 后重载
						    $.ajax({
							    type: "GET",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/user/rand_one",
							    data: {},
							    headers: { //通过 request 头传递
						          'access-token': layui.data('layuiAdmin').access_token
						        },
								success: function(data){
									$('#user_nickname').val(data.data.nickname);
									$('#user_id').val(data.data.user_id);
						            $('#avatar1').val(data.data.avatar);
					                $('#avatar').attr('src',data.data.avatar)
								},
								error: function(msg){
								  console.log(msg)
								}
							});
							return false;
				  });
		          });
		        }
		      });
		}
	});
	table.on('tool(LAY-good-list-status5)', function(obj) {
		var data = obj.data;
		if(obj.event === 'down') {
			$.ajax({
				type: "PUT",
				dataType: "json",
				url: "https://bookshop.dingdangtoy.com/api/admin/book/update_state",
				data: {
					state: '2',
					id: data.id
				},
				headers: { //通过 request 头传递
					'access-token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					layer.msg('操作成功');
					layui.table.reload('LAY-good-list-status1');
					layui.table.reload('LAY-good-list-status2');
					layui.table.reload('LAY-good-list-status3');
					layui.table.reload('LAY-good-list-status4');
					layui.table.reload('LAY-good-list-status5');
					layui.table.reload('LAY-good-list-status6');
				},
				error: function(msg) {
					console.log(msg)
				}
			});
		} else if(obj.event === 'up') {
			$.ajax({
				type: "PUT",
				dataType: "json",
				url: "https://bookshop.dingdangtoy.com/api/admin/book/update_state",
				data: {
					state: '1',
					id: data.id
				},
				headers: { //通过 request 头传递
					'access-token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					layer.msg('操作成功');
					layui.table.reload('LAY-good-list-status1');
					layui.table.reload('LAY-good-list-status2');
					layui.table.reload('LAY-good-list-status3');
					layui.table.reload('LAY-good-list-status4');
					layui.table.reload('LAY-good-list-status5');
					layui.table.reload('LAY-good-list-status6');
				},
				error: function(msg) {
					console.log(msg)
				}
			});
		} else if(obj.event === 'del') {
			layer.confirm('是否删除', function(index) {
				//        obj.del();
				//        layer.close(index);
				$.ajax({
					type: "DELETE",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/destroy",
					data: {
						id: data.id
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layer.msg('操作成功');
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
				     	layui.table.reload('LAY-good-list-status6');
						layer.close(index); //执行关闭
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		} else if(obj.event === 'edit') {
			//         location.hash = '/goods/add-goods/index/book_id='+data.id;
			admin.popup({
				title: '编辑书籍',
				area: ['90%', '90%'],
				id: 'LAY-popup-shopping-add',
				success: function(layero, index) {
					view(this.id).render('goods/add-goods/addShopping', data).done(function() {
						form.render(null, 'layuiadmin-app-form-list');
						var content_author_intro = '';
						var content_desc = '';
						var content_catalog = '';
						// 富文本
				        var E = window.wangEditor
				        var editor2 = new E('#editor2')
				        editor2.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
				            content_catalog = html
				        }
						editor2.create()
				        var editor1 = new E('#editor1')
				        editor1.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
				            content_desc = html
				        }
						editor1.create()
				        var editor = new E('#editor')
				        editor.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
                           content_author_intro = html
				        }
				        editor.create()
						function toDecimal(num, n) {
							n = n ? parseInt(n) : 0;
							if(n <= 0) {
								return Math.round(num);
							}
							num = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); //四舍五入
							num = Number(num).toFixed(n); //补足位数
							return num;
						}
//						获取详情
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/book/show?id=" + data.id,
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
                                editor.txt.html(data.data.author_intro)
                                editor1.txt.html(data.data.desc)
                                editor2.txt.html(data.data.catalog)
                                content_desc = data.data.desc;
                                content_author_intro = data.data.author_intro;
								content_catalog = data.data.catalog;
								$('#new_book_stock').val(data.data.new_book_stock);
								$('#good_book_stock').val(data.data.good_book_stock);
								$('#medium_book_stock').val(data.data.medium_book_stock);
								$('#medium_book_stock2').val(data.data.medium_book_stock2);
								$('#medium_book_stock3').val(data.data.medium_book_stock3);
								$('#medium_book_stock4').val(data.data.medium_book_stock4);
								$('#medium_book_stock5').val(data.data.medium_book_stock5);
								$('#medium_book_stock6').val(data.data.medium_book_stock6);

								$('#new_book_price').val(data.data.new_book_price);
								$('#good_book_price').val(data.data.good_book_price);
								$('#medium_book_price').val(data.data.medium_book_price);
								$('#medium_book_price2').val(data.data.medium_book_price2);
								$('#medium_book_price3').val(data.data.medium_book_price3);
								$('#medium_book_price4').val(data.data.medium_book_price4);
								$('#medium_book_price5').val(data.data.medium_book_price5);
								$('#medium_book_price6').val(data.data.medium_book_price6);

								var price1 = parseFloat(data.data.old_price);
								var price2 = parseFloat(data.data.new_book_price);
								var price3 = parseFloat(data.data.good_book_price);
								$('#new_book_discount').text(toDecimal((price2/price1)*10,1));
								$('#good_book_discount').text(toDecimal((price3/price1)*10,1));
								$('#medium_book_discount').text(toDecimal((parseFloat(data.data.medium_book_price)/price1)*10,1));
								$('#medium_book_discount2').text(toDecimal((parseFloat(data.data.medium_book_price2)/price1)*10,1));
								$('#medium_book_discount3').text(toDecimal((parseFloat(data.data.medium_book_price3)/price1)*10,1));
								$('#medium_book_discount4').text(toDecimal((parseFloat(data.data.medium_book_price4)/price1)*10,1));
								$('#medium_book_discount5').text(toDecimal((parseFloat(data.data.medium_book_price5)/price1)*10,1));
								$('#medium_book_discount6').text(toDecimal((parseFloat(data.data.medium_book_price6)/price1)*10,1));
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						// 计算总价
						$('#allPrice').on('click', function(){
							var price1 = parseFloat($('#old_price').val());
							var price2 = parseFloat($('#new_book_price').val());
							var price3 = parseFloat($('#good_book_price').val());
							var pax = price3 + (price1*0.13);
		                    $('#new_book_price').val(toDecimal(pax,1));
							$('#medium_book_price').val(toDecimal(price3*0.85,1));
							$('#medium_book_price2').val(toDecimal(price3*0.75,1));
							$('#medium_book_price3').val(toDecimal(price3*0.7,1));
							$('#medium_book_price4').val(toDecimal(price3*0.8,1));
							$('#medium_book_price5').val(toDecimal(price3*0.75,1));
							$('#medium_book_price6').val(toDecimal(price3*0.7,1));
							$('#new_book_discount').text(toDecimal((parseFloat($('#new_book_price').val())/price1)*10,1));
							$('#good_book_discount').text(toDecimal((price3/price1)*10,1));
							$('#medium_book_discount').text(toDecimal((parseFloat($('#medium_book_price').val())/price1)*10,1));
							$('#medium_book_discount2').text(toDecimal((parseFloat($('#medium_book_price2').val())/price1)*10,1));
							$('#medium_book_discount3').text(toDecimal((parseFloat($('#medium_book_price3').val())/price1)*10,1));
							$('#medium_book_discount4').text(toDecimal((parseFloat($('#medium_book_price4').val())/price1)*10,1));
							$('#medium_book_discount5').text(toDecimal((parseFloat($('#medium_book_price5').val())/price1)*10,1));
							$('#medium_book_discount6').text(toDecimal((parseFloat($('#medium_book_price6').val())/price1)*10,1));
							return false;
						});
						//上传图片
						upload.render({
							elem: '#add-goods-upload-btn',
							url: 'https://bookshop.dingdangtoy.com/api/admin/image/store',
							accept: 'images',
							method: 'get',
							acceptMime: 'image/*',
							done: function(res) {
								console.log(res.data.url)
								$('#add-goods-upload-img').attr('src', res.data.url);
								$('#add-goods-upload-image').val(res.data.url)
								//$(this.item).prev("div").children("input").val(res.data.url)
							}
						});
						var flavors = data.category_ids.split(",");
						var v1 = '';
						var v2 = '';
						// 推荐位
						var omg = data.homepage_recommend_module_ids.split(",");
						if(data.old_price) {
							v1 = data.old_price;
						}
						$('#new_book_price_discount').text((((parseFloat(data.new_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#good_book_price_discount').text((((parseFloat(data.good_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#medium_book_price_discount').text((((parseFloat(data.medium_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#recyle_price_discount').text((((parseFloat(data.recyle_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#old_price').keyup(function() {
							v1 = $(this).val();
						});
						$('#new_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#new_book_discount').text('0');
					            	} else {
					            		$('#new_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#good_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#good_book_discount').text('0');
					            	} else {
					            		$('#good_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount').text('0');
					            	} else {
					            		$('#medium_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price2').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount2').text('0');
					            	} else {
					            		$('#medium_book_discount2').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price3').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount3').text('0');
					            	} else {
					            		$('#medium_book_discount3').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price4').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount4').text('0');
					            	} else {
					            		$('#medium_book_discount4').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price5').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount5').text('0');
					            	} else {
					            		$('#medium_book_discount5').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price6').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount6').text('0');
					            	} else {
					            		$('#medium_book_discount6').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
						$('#recyle_price').keyup(function() {
							v2 = $(this).val();
							if(v1 == '') { //验证第一个是否输入
								//alert('第一个文本框不为空');
								return false;
							} else {
								if(v2 == '') {
									//alert('第二个文本框不为空');
								} else {
									if(parseFloat(v2) / parseFloat(v1) == 1) {
										$('#recyle_price_discount').text('0');
									} else {
										$('#recyle_price_discount').text((((parseFloat(v2) / parseFloat(v1)) * 10)).toFixed(1));
									}

								}
							}
						});
						// 获取二级分类
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.category_pid,
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
								var _html1 = '';
								for(var i = 0; i < data.data.length; i++) {
									if(parseInt(data.data[i].id) !==0) {
									    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
									}
								}
								$("#first-category-ids").append(_html1);
								for(var i = 0; i < flavors.length; i++) {
									$("input[name='category_ids']").each(function() {
										if($(this).val() == flavors[i]) {
											$(this).attr("checked", "checked");
										}
									})
								}
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						// 检测ISBN
						$('#detection').on('click', function() {
							//执行 Ajax 后重载
							$.ajax({
								type: "POST",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/book/check_isbn",
								data: {
									isbn: $('#isbn').val()
								},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									console.log(data)
									if(data.message) {
										$('#msg_info').text('库中已存在')
										$("#msg_info").css("color", "red");
									} else {
										$('#msg_info').text('库中不存在')
										$("#msg_info").css("color", "blue");
									}
								},
								error: function(msg) {
									console.log(msg)
								}
							});
							return false;
						});
						form.on('radio(category-pid)', function(data) {
							$("#first-category-ids").empty();
							// 获取二级分类
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.value,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									var _html1 = '';
									for(var i = 0; i < data.data.length; i++) {
										if(parseInt(data.data[i].id) !==0) {
										    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
										}
									}
									$("#first-category-ids").append(_html1);
									form.render();
								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
						// 获取推荐位
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/homepage_recommend_module/index",
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
								var _html = '';
								for(var i = 0; i < data.data.length; i++) {
									_html += '<input type="checkbox" name="homepage_recommend_module_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
								}     
								$("#first-homepage-recommend-module-ids").append(_html);
								for(var i = 0; i < omg.length; i++) {
									$("input[name='homepage_recommend_module_ids']").each(function() {
										if($(this).val() == omg[i]) {
											$(this).attr("checked", "checked");
										}
									})
								}
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						form.on('radio(category-pid)', function(data) {
							$("#first-category-ids").empty();
							// 获取二级分类
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.value,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									var _html1 = '';
									for(var i = 0; i < data.data.length; i++) {
										if(parseInt(data.data[i].id) !==0) {
										    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
										}
									}
									$("#first-category-ids").append(_html1);
									form.render();
								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
						// 监听提交
						form.on('submit(layuiadmin-app-form-submit)', function(data) {
							var field = data.field; //获取提交的字段
							//提交 Ajax 成功后，关闭当前弹层并重载表格

							var arr = new Array();
							var arr_z = new Array();   
							$("input:checkbox[name='category_ids']:checked").each(function(i) {     
								arr[i] = $(this).val();  
							});
							$("input:checkbox[name='homepage_recommend_module_ids']:checked").each(function(s) {     
								arr_z[s] = $(this).val();  
							});   
							data.field.category_ids = arr.join(","); //将数组合并成字符串
							data.field.homepage_recommend_module_ids = arr_z.join(","); //将数组合并成字符串
							//执行 Ajax 后重载
							$.ajax({
								type: "PUT",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/book/update",
								data: {
									id: data.field.id,
									'category_pid': data.field.category_pid,
									'category_ids': data.field.category_ids,
									'title': data.field.title,
									'author': data.field.author,
									'sub_title': data.field.sub_title,
									'score': data.field.score,
									'image': data.field.image,
									'author_intro': content_author_intro,
									'publish_house': data.field.publish_house,
									'publish_time': data.field.publish_time,
									'publish_num': data.field.publish_num,
									'publish_translator': data.field.publish_translator,
									'publish_package': data.field.publish_package,
									'publish_paper': data.field.publish_paper,
									'publish_pages': data.field.publish_pages,
									'publish_open': data.field.publish_open,
									'isbn': data.field.isbn,
									'desc': content_desc,
									'catalog': content_catalog,
									'old_price': data.field.old_price,
									'new_book_price': data.field.new_book_price,
									'new_book_stock': data.field.new_book_stock,
									'good_book_price': data.field.good_book_price,
									'good_book_stock': data.field.good_book_stock,
									'medium_book_price': data.field.medium_book_price,
									'medium_book_stock': data.field.medium_book_stock,
									'medium_book_price2':data.field.medium_book_price2,
									'medium_book_stock2':data.field.medium_book_stock2,
									'medium_book_price3':data.field.medium_book_price3,
									'medium_book_stock3':data.field.medium_book_stock3,
									'medium_book_price4':data.field.medium_book_price4,
									'medium_book_stock4':data.field.medium_book_stock4,
									'medium_book_price5':data.field.medium_book_price5,
									'medium_book_stock5':data.field.medium_book_stock5,
									'medium_book_price6':data.field.medium_book_price6,
									'medium_book_stock6':data.field.medium_book_stock6,
									'is_recycle': data.field.is_recycle,
									'is_sult': data.field.is_sult,
									'recyle_price': data.field.recyle_price,
									'homepage_recommend_module_ids': data.field.homepage_recommend_module_ids
								},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									if(data.code == 0) {
										layer.msg('操作成功');
										layui.table.reload('LAY-good-list-status1');
										layui.table.reload('LAY-good-list-status2');
										layui.table.reload('LAY-good-list-status3');
										layui.table.reload('LAY-good-list-status4');
										layui.table.reload('LAY-good-list-status5');
					                    layui.table.reload('LAY-good-list-status6');
										// 执行关闭
										layer.close(index);
									} else {
										layer.msg(data.message);
									}

								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
					});
				}
			});

		} else if(obj.event === 'tips1') {
			admin.popup({
				title: '查看',
				area: ['400px', '350px'],
				id: 'LAY-popup-content-edit',
				success: function(layero, index) {
					view(this.id).render('goods/goods-list/price', data).done(function() {
						form.render(null, 'layuiadmin-form-tags1');
					});
				}
			});
		} else if(obj.event === 'tips2') {
			admin.popup({
				title: '查看',
				area: ['400px', '350px'],
				id: 'LAY-popup-content-edit1',
				success: function(layero, index) {
					view(this.id).render('goods/goods-list/stock', data).done(function() {
						form.render(null, 'layuiadmin-form-tags2');
					});
				}
			});
		} else if (obj.event === 'comment') {
		      admin.popup({
		        title: '编辑评论'
		        ,area: ['80%', '80%']
		        ,id: 'LAY-popup-comment-edit'
		        ,success: function(layero, index){
		          view(this.id).render('goods/goods-list/comment', data).done(function(){
		            form.render(null, 'layuiadmin-comment-list');
		            var book_id = data.id;
				    var cols = [[
				             {field:'user_avatar', title: '用户头像',templet: '#LAY-good-list-table-stock19',width:120,align: 'center'},
				             {field:'user_nickname', title: '用户'}
				            ,{field:'content', title: '评价内容'}
				            ,{field:'score', title: '评分'}
				            ,{width:178, align:'center', fixed: 'right',title: '操作', toolbar: '#LAY-good-list-table-edit1'}
				          ]];
					  table.set({
					    headers: { //通过 request 头传递
					      'access-token': layui.data('layuiAdmin').access_token
					    }
					  });
					  // 删除评论
					  table.on('tool(LAY-good-comment)', function(obj){
					  	var data = obj.data;
					  	if(obj.event === 'del'){
				        layer.confirm('是否删除', function(index){
				   	    $.ajax({
							    type: "DELETE",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/destroy",
							    data: {id:data.id},
							    headers: { //通过 request 头传递
					              'access-token': layui.data('layuiAdmin').access_token
					            },
								success: function(data){
								    layer.msg('操作成功');
								    layui.table.reload('LAY-good-comment'); //重载表格
						        layer.close(index); //执行关闭
								},
								error: function(msg){
								  console.log(msg)
								}
							});
				        });
					  	}
					  })
				    table.render({
				      elem: '#LAY-good-comment'
				      ,url: 'https://bookshop.dingdangtoy.com/api/admin/book_comment/index?book_id='+book_id
				      ,parseData: function(res){ //res 即为原始返回的数据
				        return {
				          "code": res.code, //解析接口状态
				          "msg": res.message, //解析提示文本
				          "data": res.data.items //解析数据列表
				        }
				      }
				      ,cols: cols
				      ,page: false
				    });
				    // 获取 图书信息
				    $.ajax({
						    type: "GET",
						    dataType: "json",
						    url: "https://bookshop.dingdangtoy.com/api/admin/book/show?id="+ book_id,
						    data: {},
						    headers: { //通过 request 头传递
					          'access-token': layui.data('layuiAdmin').access_token
					        },
							success: function(data){
								console.log(data.data)
								$('#title').text(data.data.title)
								$('#author').text(data.data.author)
								$('#title').text(data.data.title)
								$('#ISBN').text(data.data.isbn)
								$('#image').attr('src',data.data.image)
								form.render();
							},
							error: function(msg){
							  console.log(msg)
							}
						});
				    form.render(null, 'add-goods-form')
				    //监听提交
				    form.on('submit(formDemo)', function(data){
				    console.log(data)
				    layer.confirm('是否执行此操作？', function(index) {
				          //执行 Ajax 后重载
						    $.ajax({
							    type: "POST",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/store",
							    data: {
							    	book_id: book_id,
							    	user_nickname: data.field.user_nickname,
							    	user_id: data.field.user_id,
							    	user_avatar: data.field.user_avatar,
							    	score: data.field.score,
							    	content: data.field.content
							    },
							    headers: { //通过 request 头传递
						          'access-token': layui.data('layuiAdmin').access_token
						        },
								success: function(data){

				          table.reload('LAY-good-comment');
				          layer.msg('操作成功');
								},
								error: function(msg){
								  console.log(msg)
								}
							});
				        });
				    return false;
				    });
				    // 随机姓名
				    $('#random').on('click', function(){
				          //执行 Ajax 后重载
						    $.ajax({
							    type: "GET",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/user/rand_one",
							    data: {},
							    headers: { //通过 request 头传递
						          'access-token': layui.data('layuiAdmin').access_token
						        },
								success: function(data){
									$('#user_nickname').val(data.data.nickname);
									$('#user_id').val(data.data.user_id);
						            $('#avatar1').val(data.data.avatar);
					                $('#avatar').attr('src',data.data.avatar)
								},
								error: function(msg){
								  console.log(msg)
								}
							});
							return false;
				  });
		          });
		        }
		      });
		}
	});

	table.on('tool(LAY-good-list-status4)', function(obj) {
		var data = obj.data;
		if(obj.event === 'down') {
			$.ajax({
				type: "PUT",
				dataType: "json",
				url: "https://bookshop.dingdangtoy.com/api/admin/book/update_state",
				data: {
					state: '2',
					id: data.id
				},
				headers: { //通过 request 头传递
					'access-token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					layer.msg('操作成功');
					layui.table.reload('LAY-good-list-status1');
					layui.table.reload('LAY-good-list-status2');
					layui.table.reload('LAY-good-list-status3');
					layui.table.reload('LAY-good-list-status4');
					layui.table.reload('LAY-good-list-status5');
					layui.table.reload('LAY-good-list-status6');
				},
				error: function(msg) {
					console.log(msg)
				}
			});
		} else if(obj.event === 'up') {
			$.ajax({
				type: "PUT",
				dataType: "json",
				url: "https://bookshop.dingdangtoy.com/api/admin/book/update_state",
				data: {
					state: '1',
					id: data.id
				},
				headers: { //通过 request 头传递
					'access-token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					layer.msg('操作成功');
					layui.table.reload('LAY-good-list-status1');
					layui.table.reload('LAY-good-list-status2');
					layui.table.reload('LAY-good-list-status3');
					layui.table.reload('LAY-good-list-status4');
					layui.table.reload('LAY-good-list-status5');
					layui.table.reload('LAY-good-list-status6');
				},
				error: function(msg) {
					console.log(msg)
				}
			});
		} else if(obj.event === 'del') {
			layer.confirm('是否删除', function(index) {
				//        obj.del();
				//        layer.close(index);
				$.ajax({
					type: "DELETE",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/destroy",
					data: {
						id: data.id
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layer.msg('操作成功');
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
				    	layui.table.reload('LAY-good-list-status6');
						layer.close(index); //执行关闭
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		} else if(obj.event === 'edit') {
			//         location.hash = '/goods/add-goods/index/book_id='+data.id;
			admin.popup({
				title: '编辑书籍',
				area: ['90%', '90%'],
				id: 'LAY-popup-shopping-add',
				success: function(layero, index) {
					view(this.id).render('goods/add-goods/addShopping', data).done(function() {
						form.render(null, 'layuiadmin-app-form-list');
						var content_author_intro = '';
						var content_desc = '';
						var content_catalog = '';
						// 富文本
				        var E = window.wangEditor
				        var editor2 = new E('#editor2')
				        editor2.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
				            content_catalog = html
				        }
						editor2.create()
				        var editor1 = new E('#editor1')
				        editor1.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
				            content_desc = html
				        }
						editor1.create()
				        var editor = new E('#editor')
				        editor.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
                           content_author_intro = html
				        }
						editor.create()
						function toDecimal(num, n) {
							n = n ? parseInt(n) : 0;
							if(n <= 0) {
								return Math.round(num);
							}
							num = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); //四舍五入
							num = Number(num).toFixed(n); //补足位数
							return num;
						}
//						获取详情
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/book/show?id=" + data.id,
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
                                editor.txt.html(data.data.author_intro)
                                editor1.txt.html(data.data.desc)
                                editor2.txt.html(data.data.catalog)
                                content_desc = data.data.desc;
                                content_author_intro = data.data.author_intro;
								content_catalog = data.data.catalog;
								$('#new_book_stock').val(data.data.new_book_stock);
								$('#good_book_stock').val(data.data.good_book_stock);
								$('#medium_book_stock').val(data.data.medium_book_stock);
								$('#medium_book_stock2').val(data.data.medium_book_stock2);
								$('#medium_book_stock3').val(data.data.medium_book_stock3);
								$('#medium_book_stock4').val(data.data.medium_book_stock4);
								$('#medium_book_stock5').val(data.data.medium_book_stock5);
								$('#medium_book_stock6').val(data.data.medium_book_stock6);

								$('#new_book_price').val(data.data.new_book_price);
								$('#good_book_price').val(data.data.good_book_price);
								$('#medium_book_price').val(data.data.medium_book_price);
								$('#medium_book_price2').val(data.data.medium_book_price2);
								$('#medium_book_price3').val(data.data.medium_book_price3);
								$('#medium_book_price4').val(data.data.medium_book_price4);
								$('#medium_book_price5').val(data.data.medium_book_price5);
								$('#medium_book_price6').val(data.data.medium_book_price6);

								var price1 = parseFloat(data.data.old_price);
								var price2 = parseFloat(data.data.new_book_price);
								var price3 = parseFloat(data.data.good_book_price);
								$('#new_book_discount').text(toDecimal((price2/price1)*10,1));
								$('#good_book_discount').text(toDecimal((price3/price1)*10,1));
								$('#medium_book_discount').text(toDecimal((parseFloat(data.data.medium_book_price)/price1)*10,1));
								$('#medium_book_discount2').text(toDecimal((parseFloat(data.data.medium_book_price2)/price1)*10,1));
								$('#medium_book_discount3').text(toDecimal((parseFloat(data.data.medium_book_price3)/price1)*10,1));
								$('#medium_book_discount4').text(toDecimal((parseFloat(data.data.medium_book_price4)/price1)*10,1));
								$('#medium_book_discount5').text(toDecimal((parseFloat(data.data.medium_book_price5)/price1)*10,1));
								$('#medium_book_discount6').text(toDecimal((parseFloat(data.data.medium_book_price6)/price1)*10,1));
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						// 计算总价
						$('#allPrice').on('click', function(){
							var price1 = parseFloat($('#old_price').val());
							var price2 = parseFloat($('#new_book_price').val());
							var price3 = parseFloat($('#good_book_price').val());
							var pax = price3 + (price1*0.13);
		                    $('#new_book_price').val(toDecimal(pax,1));
							$('#medium_book_price').val(toDecimal(price3*0.85,1));
							$('#medium_book_price2').val(toDecimal(price3*0.75,1));
							$('#medium_book_price3').val(toDecimal(price3*0.7,1));
							$('#medium_book_price4').val(toDecimal(price3*0.8,1));
							$('#medium_book_price5').val(toDecimal(price3*0.75,1));
							$('#medium_book_price6').val(toDecimal(price3*0.7,1));
							$('#new_book_discount').text(toDecimal((parseFloat($('#new_book_price').val())/price1)*10,1));
							$('#good_book_discount').text(toDecimal((price3/price1)*10,1));
							$('#medium_book_discount').text(toDecimal((parseFloat($('#medium_book_price').val())/price1)*10,1));
							$('#medium_book_discount2').text(toDecimal((parseFloat($('#medium_book_price2').val())/price1)*10,1));
							$('#medium_book_discount3').text(toDecimal((parseFloat($('#medium_book_price3').val())/price1)*10,1));
							$('#medium_book_discount4').text(toDecimal((parseFloat($('#medium_book_price4').val())/price1)*10,1));
							$('#medium_book_discount5').text(toDecimal((parseFloat($('#medium_book_price5').val())/price1)*10,1));
							$('#medium_book_discount6').text(toDecimal((parseFloat($('#medium_book_price6').val())/price1)*10,1));
							return false;
						});
						//上传图片
						upload.render({
							elem: '#add-goods-upload-btn',
							url: 'https://bookshop.dingdangtoy.com/api/admin/image/store',
							accept: 'images',
							method: 'get',
							acceptMime: 'image/*',
							done: function(res) {
								console.log(res.data.url)
								$('#add-goods-upload-img').attr('src', res.data.url);
								$('#add-goods-upload-image').val(res.data.url)
								//$(this.item).prev("div").children("input").val(res.data.url)
							}
						});
						var flavors = data.category_ids.split(",");
						var v1 = '';
						var v2 = '';
						// 推荐位
						var omg = data.homepage_recommend_module_ids.split(",");
						if(data.old_price) {
							v1 = data.old_price;
						}
						$('#new_book_price_discount').text((((parseFloat(data.new_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#good_book_price_discount').text((((parseFloat(data.good_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#medium_book_price_discount').text((((parseFloat(data.medium_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#recyle_price_discount').text((((parseFloat(data.recyle_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#old_price').keyup(function() {
							v1 = $(this).val();
						});
						$('#new_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#new_book_discount').text('0');
					            	} else {
					            		$('#new_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#good_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#good_book_discount').text('0');
					            	} else {
					            		$('#good_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount').text('0');
					            	} else {
					            		$('#medium_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price2').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount2').text('0');
					            	} else {
					            		$('#medium_book_discount2').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price3').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount3').text('0');
					            	} else {
					            		$('#medium_book_discount3').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price4').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount4').text('0');
					            	} else {
					            		$('#medium_book_discount4').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price5').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount5').text('0');
					            	} else {
					            		$('#medium_book_discount5').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price6').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount6').text('0');
					            	} else {
					            		$('#medium_book_discount6').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
						$('#recyle_price').keyup(function() {
							v2 = $(this).val();
							if(v1 == '') { //验证第一个是否输入
								//alert('第一个文本框不为空');
								return false;
							} else {
								if(v2 == '') {
									//alert('第二个文本框不为空');
								} else {
									if(parseFloat(v2) / parseFloat(v1) == 1) {
										$('#recyle_price_discount').text('0');
									} else {
										$('#recyle_price_discount').text((((parseFloat(v2) / parseFloat(v1)) * 10)).toFixed(1));
									}

								}
							}
						});
						// 获取二级分类
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.category_pid,
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
								var _html1 = '';
								for(var i = 0; i < data.data.length; i++) {
									if(parseInt(data.data[i].id) !==0) {
									    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
									}
								}
								$("#first-category-ids").append(_html1);
								for(var i = 0; i < flavors.length; i++) {
									$("input[name='category_ids']").each(function() {
										if($(this).val() == flavors[i]) {
											$(this).attr("checked", "checked");
										}
									})
								}
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						// 检测ISBN
						$('#detection').on('click', function() {
							//执行 Ajax 后重载
							$.ajax({
								type: "POST",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/book/check_isbn",
								data: {
									isbn: $('#isbn').val()
								},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									console.log(data)
									if(data.message) {
										$('#msg_info').text('库中已存在')
										$("#msg_info").css("color", "red");
									} else {
										$('#msg_info').text('库中不存在')
										$("#msg_info").css("color", "blue");
									}
								},
								error: function(msg) {
									console.log(msg)
								}
							});
							return false;
						});
						form.on('radio(category-pid)', function(data) {
							$("#first-category-ids").empty();
							// 获取二级分类
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.value,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									var _html1 = '';
									for(var i = 0; i < data.data.length; i++) {
										if(parseInt(data.data[i].id) !==0) {
										    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
										}
									}
									$("#first-category-ids").append(_html1);
									form.render();
								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
						// 获取推荐位
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/homepage_recommend_module/index",
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
								var _html = '';
								for(var i = 0; i < data.data.length; i++) {
									_html += '<input type="checkbox" name="homepage_recommend_module_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
								}     
								$("#first-homepage-recommend-module-ids").append(_html);
								for(var i = 0; i < omg.length; i++) {
									$("input[name='homepage_recommend_module_ids']").each(function() {
										if($(this).val() == omg[i]) {
											$(this).attr("checked", "checked");
										}
									})
								}
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						form.on('radio(category-pid)', function(data) {
							$("#first-category-ids").empty();
							// 获取二级分类
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.value,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									var _html1 = '';
									for(var i = 0; i < data.data.length; i++) {
										if(parseInt(data.data[i].id) !==0) {
										    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
										}
									}
									$("#first-category-ids").append(_html1);
									form.render();
								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
						// 监听提交
						form.on('submit(layuiadmin-app-form-submit)', function(data) {
							var field = data.field; //获取提交的字段
							//提交 Ajax 成功后，关闭当前弹层并重载表格

							var arr = new Array();
							var arr_z = new Array();   
							$("input:checkbox[name='category_ids']:checked").each(function(i) {     
								arr[i] = $(this).val();  
							});
							$("input:checkbox[name='homepage_recommend_module_ids']:checked").each(function(s) {     
								arr_z[s] = $(this).val();  
							});   
							data.field.category_ids = arr.join(","); //将数组合并成字符串
							data.field.homepage_recommend_module_ids = arr_z.join(","); //将数组合并成字符串
							//执行 Ajax 后重载
							$.ajax({
								type: "PUT",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/book/update",
								data: {
									id: data.field.id,
									'category_pid': data.field.category_pid,
									'category_ids': data.field.category_ids,
									'title': data.field.title,
									'author': data.field.author,
									'sub_title': data.field.sub_title,
									'score': data.field.score,
									'image': data.field.image,
									'author_intro': content_author_intro,
									'publish_house': data.field.publish_house,
									'publish_time': data.field.publish_time,
									'publish_num': data.field.publish_num,
									'publish_translator': data.field.publish_translator,
									'publish_package': data.field.publish_package,
									'publish_paper': data.field.publish_paper,
									'publish_pages': data.field.publish_pages,
									'publish_open': data.field.publish_open,
									'isbn': data.field.isbn,
									'desc': content_desc,
									'catalog': content_catalog,
									'old_price': data.field.old_price,
									'new_book_price': data.field.new_book_price,
									'new_book_stock': data.field.new_book_stock,
									'good_book_price': data.field.good_book_price,
									'good_book_stock': data.field.good_book_stock,
									'medium_book_price': data.field.medium_book_price,
									'medium_book_stock': data.field.medium_book_stock,
									'medium_book_price2':data.field.medium_book_price2,
									'medium_book_stock2':data.field.medium_book_stock2,
									'medium_book_price3':data.field.medium_book_price3,
									'medium_book_stock3':data.field.medium_book_stock3,
									'medium_book_price4':data.field.medium_book_price4,
									'medium_book_stock4':data.field.medium_book_stock4,
									'medium_book_price5':data.field.medium_book_price5,
									'medium_book_stock5':data.field.medium_book_stock5,
									'medium_book_price6':data.field.medium_book_price6,
									'medium_book_stock6':data.field.medium_book_stock6,
									'is_recycle': data.field.is_recycle,
									'is_sult': data.field.is_sult,
									'recyle_price': data.field.recyle_price,
									'homepage_recommend_module_ids': data.field.homepage_recommend_module_ids
								},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									if(data.code == 0) {
										layer.msg('操作成功');
										layui.table.reload('LAY-good-list-status1');
										layui.table.reload('LAY-good-list-status2');
										layui.table.reload('LAY-good-list-status3');
										layui.table.reload('LAY-good-list-status4');
										layui.table.reload('LAY-good-list-status5');
					                    layui.table.reload('LAY-good-list-status6');
										// 执行关闭
										layer.close(index);
									} else {
										layer.msg(data.message);
									}

								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
					});
				}
			});

		} else if(obj.event === 'tips1') {
			admin.popup({
				title: '查看',
				area: ['400px', '350px'],
				id: 'LAY-popup-content-edit',
				success: function(layero, index) {
					view(this.id).render('goods/goods-list/price', data).done(function() {
						form.render(null, 'layuiadmin-form-tags1');
					});
				}
			});
		} else if(obj.event === 'tips2') {
			admin.popup({
				title: '查看',
				area: ['400px', '350px'],
				id: 'LAY-popup-content-edit1',
				success: function(layero, index) {
					view(this.id).render('goods/goods-list/stock', data).done(function() {
						form.render(null, 'layuiadmin-form-tags2');
					});
				}
			});
		} else if (obj.event === 'comment') {
		      admin.popup({
		        title: '编辑评论'
		        ,area: ['80%', '80%']
		        ,id: 'LAY-popup-comment-edit'
		        ,success: function(layero, index){
		          view(this.id).render('goods/goods-list/comment', data).done(function(){
		            form.render(null, 'layuiadmin-comment-list');
		            var book_id = data.id;
				    var cols = [[
				             {field:'user_avatar', title: '用户头像',templet: '#LAY-good-list-table-stock19',width:120,align: 'center'},
				             {field:'user_nickname', title: '用户'}
				            ,{field:'content', title: '评价内容'}
				            ,{field:'score', title: '评分'}
				            ,{width:178, align:'center', fixed: 'right',title: '操作', toolbar: '#LAY-good-list-table-edit1'}
				          ]];
					  table.set({
					    headers: { //通过 request 头传递
					      'access-token': layui.data('layuiAdmin').access_token
					    }
					  });
					  // 删除评论
					  table.on('tool(LAY-good-comment)', function(obj){
					  	var data = obj.data;
					  	if(obj.event === 'del'){
				        layer.confirm('是否删除', function(index){
				   	    $.ajax({
							    type: "DELETE",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/destroy",
							    data: {id:data.id},
							    headers: { //通过 request 头传递
					              'access-token': layui.data('layuiAdmin').access_token
					            },
								success: function(data){
								    layer.msg('操作成功');
								    layui.table.reload('LAY-good-comment'); //重载表格
						        layer.close(index); //执行关闭
								},
								error: function(msg){
								  console.log(msg)
								}
							});
				        });
					  	}
					  })
				    table.render({
				      elem: '#LAY-good-comment'
				      ,url: 'https://bookshop.dingdangtoy.com/api/admin/book_comment/index?book_id='+book_id
				      ,parseData: function(res){ //res 即为原始返回的数据
				        return {
				          "code": res.code, //解析接口状态
				          "msg": res.message, //解析提示文本
				          "data": res.data.items //解析数据列表
				        }
				      }
				      ,cols: cols
				      ,page: false
				    });
				    // 获取 图书信息
				    $.ajax({
						    type: "GET",
						    dataType: "json",
						    url: "https://bookshop.dingdangtoy.com/api/admin/book/show?id="+ book_id,
						    data: {},
						    headers: { //通过 request 头传递
					          'access-token': layui.data('layuiAdmin').access_token
					        },
							success: function(data){
								console.log(data.data)
								$('#title').text(data.data.title)
								$('#author').text(data.data.author)
								$('#title').text(data.data.title)
								$('#ISBN').text(data.data.isbn)
								$('#image').attr('src',data.data.image)
								form.render();
							},
							error: function(msg){
							  console.log(msg)
							}
						});
				    form.render(null, 'add-goods-form')
				    //监听提交
				    form.on('submit(formDemo)', function(data){
				    console.log(data)
				    layer.confirm('是否执行此操作？', function(index) {
				          //执行 Ajax 后重载
						    $.ajax({
							    type: "POST",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/store",
							    data: {
							    	book_id: book_id,
							    	user_nickname: data.field.user_nickname,
							    	user_id: data.field.user_id,
							    	user_avatar: data.field.user_avatar,
							    	score: data.field.score,
							    	content: data.field.content
							    },
							    headers: { //通过 request 头传递
						          'access-token': layui.data('layuiAdmin').access_token
						        },
								success: function(data){

				          table.reload('LAY-good-comment');
				          layer.msg('操作成功');
								},
								error: function(msg){
								  console.log(msg)
								}
							});
				        });
				    return false;
				    });
				    // 随机姓名
				    $('#random').on('click', function(){
				          //执行 Ajax 后重载
						    $.ajax({
							    type: "GET",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/user/rand_one",
							    data: {},
							    headers: { //通过 request 头传递
						          'access-token': layui.data('layuiAdmin').access_token
						        },
								success: function(data){
									$('#user_nickname').val(data.data.nickname);
									$('#user_id').val(data.data.user_id);
						            $('#avatar1').val(data.data.avatar);
					                $('#avatar').attr('src',data.data.avatar)
								},
								error: function(msg){
								  console.log(msg)
								}
							});
							return false;
				  });
		          });
		        }
		      });
		}
	});
	table.on('tool(LAY-good-list-status1)', function(obj) {
		var data = obj.data;
		if(obj.event === 'down') {
			$.ajax({
				type: "PUT",
				dataType: "json",
				url: "https://bookshop.dingdangtoy.com/api/admin/book/update_state",
				data: {
					state: '2',
					id: data.id
				},
				headers: { //通过 request 头传递
					'access-token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					layer.msg('操作成功');
					layui.table.reload('LAY-good-list-status1');
					layui.table.reload('LAY-good-list-status2');
					layui.table.reload('LAY-good-list-status3');
					layui.table.reload('LAY-good-list-status4');
					layui.table.reload('LAY-good-list-status5');
					layui.table.reload('LAY-good-list-status6');
				},
				error: function(msg) {
					console.log(msg)
				}
			});
		} else if(obj.event === 'up') {
			$.ajax({
				type: "PUT",
				dataType: "json",
				url: "https://bookshop.dingdangtoy.com/api/admin/book/update_state",
				data: {
					state: '1',
					id: data.id
				},
				headers: { //通过 request 头传递
					'access-token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					layer.msg('操作成功');
					layui.table.reload('LAY-good-list-status1');
					layui.table.reload('LAY-good-list-status2');
					layui.table.reload('LAY-good-list-status3');
					layui.table.reload('LAY-good-list-status4');
					layui.table.reload('LAY-good-list-status5');
					layui.table.reload('LAY-good-list-status6');
				},
				error: function(msg) {
					console.log(msg)
				}
			});
		} else if(obj.event === 'del') {
			layer.confirm('是否删除', function(index) {
				//        obj.del();
				//        layer.close(index);
				$.ajax({
					type: "DELETE",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/destroy",
					data: {
						id: data.id
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layer.msg('操作成功');
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.close(index); //执行关闭
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		} else if(obj.event === 'edit') {
			//         location.hash = '/goods/add-goods/index/book_id='+data.id;
			admin.popup({
				title: '编辑书籍',
				area: ['90%', '90%'],
				id: 'LAY-popup-shopping-add',
				success: function(layero, index) {
					view(this.id).render('goods/add-goods/addShopping', data).done(function() {
						form.render(null, 'layuiadmin-app-form-list');
						var content_author_intro = '';
						var content_desc = '';
						var content_catalog = '';
						// 富文本
				        var E = window.wangEditor
				        var editor2 = new E('#editor2')
				        editor2.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
				            content_catalog = html
				        }
						editor2.create()
				        var editor1 = new E('#editor1')
				        editor1.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
				            content_desc = html
				        }
						editor1.create()
				        var editor = new E('#editor')
				        editor.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
                           content_author_intro = html
						}
						editor.create()
						function toDecimal(num, n) {
							n = n ? parseInt(n) : 0;
							if(n <= 0) {
								return Math.round(num);
							}
							num = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); //四舍五入
							num = Number(num).toFixed(n); //补足位数
							return num;
						}
//						获取详情
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/book/show?id=" + data.id,
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
                                editor.txt.html(data.data.author_intro)
                                editor1.txt.html(data.data.desc)
                                editor2.txt.html(data.data.catalog)
                                content_desc = data.data.desc;
                                content_author_intro = data.data.author_intro;
								content_catalog = data.data.catalog;
								$('#new_book_stock').val(data.data.new_book_stock);
								$('#good_book_stock').val(data.data.good_book_stock);
								$('#medium_book_stock').val(data.data.medium_book_stock);
								$('#medium_book_stock2').val(data.data.medium_book_stock2);
								$('#medium_book_stock3').val(data.data.medium_book_stock3);
								$('#medium_book_stock4').val(data.data.medium_book_stock4);
								$('#medium_book_stock5').val(data.data.medium_book_stock5);
								$('#medium_book_stock6').val(data.data.medium_book_stock6);

								$('#new_book_price').val(data.data.new_book_price);
								$('#good_book_price').val(data.data.good_book_price);
								$('#medium_book_price').val(data.data.medium_book_price);
								$('#medium_book_price2').val(data.data.medium_book_price2);
								$('#medium_book_price3').val(data.data.medium_book_price3);
								$('#medium_book_price4').val(data.data.medium_book_price4);
								$('#medium_book_price5').val(data.data.medium_book_price5);
								$('#medium_book_price6').val(data.data.medium_book_price6);

								var price1 = parseFloat(data.data.old_price);
								var price2 = parseFloat(data.data.new_book_price);
								var price3 = parseFloat(data.data.good_book_price);
								$('#new_book_discount').text(toDecimal((price2/price1)*10,1));
								$('#good_book_discount').text(toDecimal((price3/price1)*10,1));
								$('#medium_book_discount').text(toDecimal((parseFloat(data.data.medium_book_price)/price1)*10,1));
								$('#medium_book_discount2').text(toDecimal((parseFloat(data.data.medium_book_price2)/price1)*10,1));
								$('#medium_book_discount3').text(toDecimal((parseFloat(data.data.medium_book_price3)/price1)*10,1));
								$('#medium_book_discount4').text(toDecimal((parseFloat(data.data.medium_book_price4)/price1)*10,1));
								$('#medium_book_discount5').text(toDecimal((parseFloat(data.data.medium_book_price5)/price1)*10,1));
								$('#medium_book_discount6').text(toDecimal((parseFloat(data.data.medium_book_price6)/price1)*10,1));
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						// 计算总价
						$('#allPrice').on('click', function(){
							var price1 = parseFloat($('#old_price').val());
							var price2 = parseFloat($('#new_book_price').val());
							var price3 = parseFloat($('#good_book_price').val());
							var pax = price3 + (price1*0.13);
		                    $('#new_book_price').val(toDecimal(pax,1));
							$('#medium_book_price').val(toDecimal(price3*0.85,1));
							$('#medium_book_price2').val(toDecimal(price3*0.75,1));
							$('#medium_book_price3').val(toDecimal(price3*0.7,1));
							$('#medium_book_price4').val(toDecimal(price3*0.8,1));
							$('#medium_book_price5').val(toDecimal(price3*0.75,1));
							$('#medium_book_price6').val(toDecimal(price3*0.7,1));
							$('#new_book_discount').text(toDecimal((parseFloat($('#new_book_price').val())/price1)*10,1));
							$('#good_book_discount').text(toDecimal((price3/price1)*10,1));
							$('#medium_book_discount').text(toDecimal((parseFloat($('#medium_book_price').val())/price1)*10,1));
							$('#medium_book_discount2').text(toDecimal((parseFloat($('#medium_book_price2').val())/price1)*10,1));
							$('#medium_book_discount3').text(toDecimal((parseFloat($('#medium_book_price3').val())/price1)*10,1));
							$('#medium_book_discount4').text(toDecimal((parseFloat($('#medium_book_price4').val())/price1)*10,1));
							$('#medium_book_discount5').text(toDecimal((parseFloat($('#medium_book_price5').val())/price1)*10,1));
							$('#medium_book_discount6').text(toDecimal((parseFloat($('#medium_book_price6').val())/price1)*10,1));
							return false;
						});
						// $('#allPrice').on('click', function(){
					    //   var price1 = parseFloat($('#old_price ').val());
					    //   var price2 = parseFloat($('#recyle_price ').val());
					    //   var allPrice1 = ((price2*2)+(price1*0.2)).toFixed(1);
					    //   var allPrice2 = (price2*2).toFixed(1);
					    //   var allPrice3 = (price2*2*0.75).toFixed(1);
					    //   $('#new_book_price ').val(allPrice1);
					    //   $('#good_book_price ').val(allPrice2);
					    //   $('#medium_book_price ').val(allPrice3);
					    //   $('#new_book_price_discount').text((((parseFloat($('#new_book_price').val()) / parseFloat($('#old_price').val())) * 10)).toFixed(1));
						// 		$('#good_book_price_discount').text((((parseFloat($('#good_book_price').val()) / parseFloat($('#old_price').val())) * 10)).toFixed(1));
						// 		$('#medium_book_price_discount').text((((parseFloat($('#medium_book_price').val()) / parseFloat($('#old_price').val())) * 10)).toFixed(1));
						// 		return false;
					    // });
						//上传图片
						upload.render({
							elem: '#add-goods-upload-btn',
							url: 'https://bookshop.dingdangtoy.com/api/admin/image/store',
							accept: 'images',
							method: 'get',
							acceptMime: 'image/*',
							done: function(res) {
								console.log(res.data.url)
								$('#add-goods-upload-img').attr('src', res.data.url);
								$('#add-goods-upload-image').val(res.data.url)
								//$(this.item).prev("div").children("input").val(res.data.url)
							}
						});
						var flavors = data.category_ids.split(",");
						var v1 = '';
						var v2 = '';
						// 推荐位
						var omg = data.homepage_recommend_module_ids.split(",");
						if(data.old_price) {
							v1 = data.old_price;
						}
						$('#new_book_price_discount').text((((parseFloat(data.new_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#good_book_price_discount').text((((parseFloat(data.good_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#medium_book_price_discount').text((((parseFloat(data.medium_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#recyle_price_discount').text((((parseFloat(data.recyle_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#old_price').keyup(function() {
							v1 = $(this).val();
						});
						$('#new_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#new_book_discount').text('0');
					            	} else {
					            		$('#new_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#good_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#good_book_discount').text('0');
					            	} else {
					            		$('#good_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount').text('0');
					            	} else {
					            		$('#medium_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price2').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount2').text('0');
					            	} else {
					            		$('#medium_book_discount2').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price3').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount3').text('0');
					            	} else {
					            		$('#medium_book_discount3').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price4').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount4').text('0');
					            	} else {
					            		$('#medium_book_discount4').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price5').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount5').text('0');
					            	} else {
					            		$('#medium_book_discount5').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price6').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount6').text('0');
					            	} else {
					            		$('#medium_book_discount6').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
						$('#recyle_price').keyup(function() {
							v2 = $(this).val();
							if(v1 == '') { //验证第一个是否输入
								//alert('第一个文本框不为空');
								return false;
							} else {
								if(v2 == '') {
									//alert('第二个文本框不为空');
								} else {
									if(parseFloat(v2) / parseFloat(v1) == 1) {
										$('#recyle_price_discount').text('0');
									} else {
										$('#recyle_price_discount').text((((parseFloat(v2) / parseFloat(v1)) * 10)).toFixed(1));
									}

								}
							}
						});
						// 获取二级分类
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.category_pid,
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
								var _html1 = '';
								for(var i = 0; i < data.data.length; i++) {
									if(parseInt(data.data[i].id) !==0) {
									    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
									}
								}
								$("#first-category-ids").append(_html1);
								for(var i = 0; i < flavors.length; i++) {
									$("input[name='category_ids']").each(function() {
										if($(this).val() == flavors[i]) {
											$(this).attr("checked", "checked");
										}
									})
								}
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						// 检测ISBN
						$('#detection').on('click', function() {
							//执行 Ajax 后重载
							$.ajax({
								type: "POST",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/book/check_isbn",
								data: {
									isbn: $('#isbn').val()
								},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									console.log(data)
									if(data.message) {
										$('#msg_info').text('库中已存在')
										$("#msg_info").css("color", "red");
									} else {
										$('#msg_info').text('库中不存在')
										$("#msg_info").css("color", "blue");
									}
								},
								error: function(msg) {
									console.log(msg)
								}
							});
							return false;
						});
						form.on('radio(category-pid)', function(data) {
							$("#first-category-ids").empty();
							// 获取二级分类
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.value,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									var _html1 = '';
									for(var i = 0; i < data.data.length; i++) {
										if(parseInt(data.data[i].id) !==0) {
										    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
										}
									}
									$("#first-category-ids").append(_html1);
									form.render();
								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
						// 获取推荐位
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/homepage_recommend_module/index",
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
								var _html = '';
								for(var i = 0; i < data.data.length; i++) {
									_html += '<input type="checkbox" name="homepage_recommend_module_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
								}     
								$("#first-homepage-recommend-module-ids").append(_html);
								for(var i = 0; i < omg.length; i++) {
									$("input[name='homepage_recommend_module_ids']").each(function() {
										if($(this).val() == omg[i]) {
											$(this).attr("checked", "checked");
										}
									})
								}
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						form.on('radio(category-pid)', function(data) {
							$("#first-category-ids").empty();
							// 获取二级分类
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.value,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									var _html1 = '';
									for(var i = 0; i < data.data.length; i++) {
										if(parseInt(data.data[i].id) !==0) {
										    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
										}
									}
									$("#first-category-ids").append(_html1);
									form.render();
								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
						// 监听提交
						form.on('submit(layuiadmin-app-form-submit)', function(data) {

							var field = data.field; //获取提交的字段
							//提交 Ajax 成功后，关闭当前弹层并重载表格

							var arr = new Array();
							var arr_z = new Array();   
							$("input:checkbox[name='category_ids']:checked").each(function(i) {     
								arr[i] = $(this).val();  
							});
							$("input:checkbox[name='homepage_recommend_module_ids']:checked").each(function(s) {     
								arr_z[s] = $(this).val();  
							});   
							data.field.category_ids = arr.join(","); //将数组合并成字符串
							data.field.homepage_recommend_module_ids = arr_z.join(","); //将数组合并成字符串
							//执行 Ajax 后重载
							$.ajax({
								type: "PUT",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/book/update",
								data: {
									id: data.field.id,
									'category_pid': data.field.category_pid,
									'category_ids': data.field.category_ids,
									'title': data.field.title,
									'author': data.field.author,
									'sub_title': data.field.sub_title,
									'score': data.field.score,
									'image': data.field.image,
									'author_intro': content_author_intro,
									'publish_house': data.field.publish_house,
									'publish_time': data.field.publish_time,
									'publish_num': data.field.publish_num,
									'publish_translator': data.field.publish_translator,
									'publish_package': data.field.publish_package,
									'publish_paper': data.field.publish_paper,
									'publish_pages': data.field.publish_pages,
									'publish_open': data.field.publish_open,
									'isbn': data.field.isbn,
									'desc': content_desc,
									'catalog': content_catalog,
									'old_price': data.field.old_price,
									'new_book_price': data.field.new_book_price,
									'new_book_stock': data.field.new_book_stock,
									'good_book_price': data.field.good_book_price,
									'good_book_stock': data.field.good_book_stock,
									'medium_book_price': data.field.medium_book_price,
									'medium_book_stock': data.field.medium_book_stock,
									'medium_book_price2':data.field.medium_book_price2,
									'medium_book_stock2':data.field.medium_book_stock2,
									'medium_book_price3':data.field.medium_book_price3,
									'medium_book_stock3':data.field.medium_book_stock3,
									'medium_book_price4':data.field.medium_book_price4,
									'medium_book_stock4':data.field.medium_book_stock4,
									'medium_book_price5':data.field.medium_book_price5,
									'medium_book_stock5':data.field.medium_book_stock5,
									'medium_book_price6':data.field.medium_book_price6,
									'medium_book_stock6':data.field.medium_book_stock6,
									'is_recycle': data.field.is_recycle,
									'is_sult': data.field.is_sult,
									'recyle_price': data.field.recyle_price,
									'homepage_recommend_module_ids': data.field.homepage_recommend_module_ids
								},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									if(data.code == 0) {
										layer.msg('操作成功');
										layui.table.reload('LAY-good-list-status1');
										layui.table.reload('LAY-good-list-status2');
										layui.table.reload('LAY-good-list-status3');
										layui.table.reload('LAY-good-list-status4');
										layui.table.reload('LAY-good-list-status5');
					                    layui.table.reload('LAY-good-list-status6');
										// 执行关闭
										layer.close(index);
									} else {
										layer.msg(data.message);
									}

								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
					});
				}
			});
		} else if(obj.event === 'tips1') {
			admin.popup({
				title: '查看',
				area: ['400px', '350px'],
				id: 'LAY-popup-content-edit',
				success: function(layero, index) {
					view(this.id).render('goods/goods-list/price', data).done(function() {
						form.render(null, 'layuiadmin-form-tags1');
					});
				}
			});
		} else if(obj.event === 'tips2') {
			admin.popup({
				title: '查看',
				area: ['400px', '350px'],
				id: 'LAY-popup-content-edit1',
				success: function(layero, index) {
					view(this.id).render('goods/goods-list/stock', data).done(function() {
						form.render(null, 'layuiadmin-form-tags2');
					});
				}
			});
		} else if (obj.event === 'comment') {
		      admin.popup({
		        title: '编辑评论'
		        ,area: ['80%', '80%']
		        ,id: 'LAY-popup-comment-edit'
		        ,success: function(layero, index){
		          view(this.id).render('goods/goods-list/comment', data).done(function(){
		            form.render(null, 'layuiadmin-comment-list');
		            var book_id = data.id;
				    var cols = [[
				             {field:'user_avatar', title: '用户头像',templet: '#LAY-good-list-table-stock19',width:120,align: 'center'},
				             {field:'user_nickname', title: '用户'}
				            ,{field:'content', title: '评价内容'}
				            ,{field:'score', title: '评分'}
				            ,{width:178, align:'center', fixed: 'right',title: '操作', toolbar: '#LAY-good-list-table-edit1'}
				          ]];
					  table.set({
					    headers: { //通过 request 头传递
					      'access-token': layui.data('layuiAdmin').access_token
					    }
					  });
					  // 删除评论
					  table.on('tool(LAY-good-comment)', function(obj){
					  	var data = obj.data;
					  	if(obj.event === 'del'){
				        layer.confirm('是否删除', function(index){
				   	    $.ajax({
							    type: "DELETE",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/destroy",
							    data: {id:data.id},
							    headers: { //通过 request 头传递
					              'access-token': layui.data('layuiAdmin').access_token
					            },
								success: function(data){
								    layer.msg('操作成功');
								    layui.table.reload('LAY-good-comment'); //重载表格
						        layer.close(index); //执行关闭
								},
								error: function(msg){
								  console.log(msg)
								}
							});
				        });
					  	}
					  })
				    table.render({
				      elem: '#LAY-good-comment'
				      ,url: 'https://bookshop.dingdangtoy.com/api/admin/book_comment/index?book_id='+book_id
				      ,parseData: function(res){ //res 即为原始返回的数据
				        return {
				          "code": res.code, //解析接口状态
				          "msg": res.message, //解析提示文本
				          "data": res.data.items //解析数据列表
				        }
				      }
				      ,cols: cols
				      ,page: false
				    });
				    // 获取 图书信息
				    $.ajax({
						    type: "GET",
						    dataType: "json",
						    url: "https://bookshop.dingdangtoy.com/api/admin/book/show?id="+ book_id,
						    data: {},
						    headers: { //通过 request 头传递
					          'access-token': layui.data('layuiAdmin').access_token
					        },
							success: function(data){
								console.log(data.data)
								$('#title').text(data.data.title)
								$('#author').text(data.data.author)
								$('#title').text(data.data.title)
								$('#ISBN').text(data.data.isbn)
								$('#image').attr('src',data.data.image)
								form.render();
							},
							error: function(msg){
							  console.log(msg)
							}
						});
				    form.render(null, 'add-goods-form')
				    //监听提交
				    form.on('submit(formDemo)', function(data){
				    console.log(data)
				    layer.confirm('是否执行此操作？', function(index) {
				          //执行 Ajax 后重载
						    $.ajax({
							    type: "POST",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/store",
							    data: {
							    	book_id: book_id,
							    	user_nickname: data.field.user_nickname,
							    	user_id: data.field.user_id,
							    	user_avatar: data.field.user_avatar,
							    	score: data.field.score,
							    	content: data.field.content
							    },
							    headers: { //通过 request 头传递
						          'access-token': layui.data('layuiAdmin').access_token
						        },
								success: function(data){

				          table.reload('LAY-good-comment');
				          layer.msg('操作成功');
								},
								error: function(msg){
								  console.log(msg)
								}
							});
				        });
				    return false;
				    });
				    // 随机姓名
				    $('#random').on('click', function(){
				          //执行 Ajax 后重载
						    $.ajax({
							    type: "GET",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/user/rand_one",
							    data: {},
							    headers: { //通过 request 头传递
						          'access-token': layui.data('layuiAdmin').access_token
						        },
								success: function(data){
									$('#user_nickname').val(data.data.nickname);
									$('#user_id').val(data.data.user_id);
						            $('#avatar1').val(data.data.avatar);
					                $('#avatar').attr('src',data.data.avatar)
								},
								error: function(msg){
								  console.log(msg)
								}
							});
							return false;
				  });
		          });
		        }
		      });
		}
	});
	table.on('tool(LAY-good-list-status2)', function(obj) {
		var data = obj.data;
		if(obj.event === 'down') {
			$.ajax({
				type: "PUT",
				dataType: "json",
				url: "https://bookshop.dingdangtoy.com/api/admin/book/update_state",
				data: {
					state: '2',
					id: data.id
				},
				headers: { //通过 request 头传递
					'access-token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					layer.msg('操作成功');
					layui.table.reload('LAY-good-list-status1');
					layui.table.reload('LAY-good-list-status2');
					layui.table.reload('LAY-good-list-status3');
					layui.table.reload('LAY-good-list-status4');
					layui.table.reload('LAY-good-list-status5');
					layui.table.reload('LAY-good-list-status6');
				},
				error: function(msg) {
					console.log(msg)
				}
			});
		} else if(obj.event === 'up') {
			$.ajax({
				type: "PUT",
				dataType: "json",
				url: "https://bookshop.dingdangtoy.com/api/admin/book/update_state",
				data: {
					state: '1',
					id: data.id
				},
				headers: { //通过 request 头传递
					'access-token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					layer.msg('操作成功');
					layui.table.reload('LAY-good-list-status1');
					layui.table.reload('LAY-good-list-status2');
					layui.table.reload('LAY-good-list-status3');
					layui.table.reload('LAY-good-list-status4');
					layui.table.reload('LAY-good-list-status5');
					layui.table.reload('LAY-good-list-status6');
				},
				error: function(msg) {
					console.log(msg)
				}
			});
		} else if(obj.event === 'del') {
			layer.confirm('是否删除', function(index) {
				//        obj.del();
				//        layer.close(index);
				$.ajax({
					type: "DELETE",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/destroy",
					data: {
						id: data.id
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layer.msg('操作成功');
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.close(index); //执行关闭
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		} else if(obj.event === 'edit') {
			//         location.hash = '/goods/add-goods/index/book_id='+data.id;
			admin.popup({
				title: '编辑书籍',
				area: ['90%', '90%'],
				id: 'LAY-popup-shopping-add',
				success: function(layero, index) {
					view(this.id).render('goods/add-goods/addShopping', data).done(function() {
						form.render(null, 'layuiadmin-app-form-list');
						var content_author_intro = '';
						var content_desc = '';
						var content_catalog = '';
						// 富文本
				        var E = window.wangEditor
				        var editor2 = new E('#editor2')
				        editor2.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
				            content_catalog = html
				        }
						editor2.create()
				        var editor1 = new E('#editor1')
				        editor1.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
				            content_desc = html
				        }
						editor1.create()
				        var editor = new E('#editor')
				        editor.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
                           content_author_intro = html
				        }
						editor.create()
						function toDecimal(num, n) {
							n = n ? parseInt(n) : 0;
							if(n <= 0) {
								return Math.round(num);
							}
							num = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); //四舍五入
							num = Number(num).toFixed(n); //补足位数
							return num;
						}
//						获取详情
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/book/show?id=" + data.id,
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
                                editor.txt.html(data.data.author_intro)
                                editor1.txt.html(data.data.desc)
                                editor2.txt.html(data.data.catalog)
                                content_desc = data.data.desc;
                                content_author_intro = data.data.author_intro;
								content_catalog = data.data.catalog;
								$('#new_book_stock').val(data.data.new_book_stock);
								$('#good_book_stock').val(data.data.good_book_stock);
								$('#medium_book_stock').val(data.data.medium_book_stock);
								$('#medium_book_stock2').val(data.data.medium_book_stock2);
								$('#medium_book_stock3').val(data.data.medium_book_stock3);
								$('#medium_book_stock4').val(data.data.medium_book_stock4);
								$('#medium_book_stock5').val(data.data.medium_book_stock5);
								$('#medium_book_stock6').val(data.data.medium_book_stock6);

								$('#new_book_price').val(data.data.new_book_price);
								$('#good_book_price').val(data.data.good_book_price);
								$('#medium_book_price').val(data.data.medium_book_price);
								$('#medium_book_price2').val(data.data.medium_book_price2);
								$('#medium_book_price3').val(data.data.medium_book_price3);
								$('#medium_book_price4').val(data.data.medium_book_price4);
								$('#medium_book_price5').val(data.data.medium_book_price5);
								$('#medium_book_price6').val(data.data.medium_book_price6);

								var price1 = parseFloat(data.data.old_price);
								var price2 = parseFloat(data.data.new_book_price);
								var price3 = parseFloat(data.data.good_book_price);
								$('#new_book_discount').text(toDecimal((price2/price1)*10,1));
								$('#good_book_discount').text(toDecimal((price3/price1)*10,1));
								$('#medium_book_discount').text(toDecimal((parseFloat(data.data.medium_book_price)/price1)*10,1));
								$('#medium_book_discount2').text(toDecimal((parseFloat(data.data.medium_book_price2)/price1)*10,1));
								$('#medium_book_discount3').text(toDecimal((parseFloat(data.data.medium_book_price3)/price1)*10,1));
								$('#medium_book_discount4').text(toDecimal((parseFloat(data.data.medium_book_price4)/price1)*10,1));
								$('#medium_book_discount5').text(toDecimal((parseFloat(data.data.medium_book_price5)/price1)*10,1));
								$('#medium_book_discount6').text(toDecimal((parseFloat(data.data.medium_book_price6)/price1)*10,1));
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						// 计算总价
						$('#allPrice').on('click', function(){
							var price1 = parseFloat($('#old_price').val());
							var price2 = parseFloat($('#new_book_price').val());
							var price3 = parseFloat($('#good_book_price').val());
							var pax = price3 + (price1*0.13);
		                    $('#new_book_price').val(toDecimal(pax,1));
							$('#medium_book_price').val(toDecimal(price3*0.85,1));
							$('#medium_book_price2').val(toDecimal(price3*0.75,1));
							$('#medium_book_price3').val(toDecimal(price3*0.7,1));
							$('#medium_book_price4').val(toDecimal(price3*0.8,1));
							$('#medium_book_price5').val(toDecimal(price3*0.75,1));
							$('#medium_book_price6').val(toDecimal(price3*0.7,1));
							$('#new_book_discount').text(toDecimal((price2/price1)*10,1));
							$('#good_book_discount').text(toDecimal((price3/price1)*10,1));
							$('#medium_book_discount').text(toDecimal((parseFloat($('#medium_book_price').val())/price1)*10,1));
							$('#medium_book_discount2').text(toDecimal((parseFloat($('#medium_book_price2').val())/price1)*10,1));
							$('#medium_book_discount3').text(toDecimal((parseFloat($('#medium_book_price3').val())/price1)*10,1));
							$('#medium_book_discount4').text(toDecimal((parseFloat($('#medium_book_price4').val())/price1)*10,1));
							$('#medium_book_discount5').text(toDecimal((parseFloat($('#medium_book_price5').val())/price1)*10,1));
							$('#medium_book_discount6').text(toDecimal((parseFloat($('#medium_book_price6').val())/price1)*10,1));
							return false;
						});
						//上传图片
						upload.render({
							elem: '#add-goods-upload-btn',
							url: 'https://bookshop.dingdangtoy.com/api/admin/image/store',
							accept: 'images',
							method: 'get',
							acceptMime: 'image/*',
							done: function(res) {
								console.log(res.data.url)
								$('#add-goods-upload-img').attr('src', res.data.url);
								$('#add-goods-upload-image').val(res.data.url)
								//$(this.item).prev("div").children("input").val(res.data.url)
							}
						});
						var flavors = data.category_ids.split(",");
						var v1 = '';
						var v2 = '';
						// 推荐位
						var omg = data.homepage_recommend_module_ids.split(",");
						if(data.old_price) {
							v1 = data.old_price;
						}
						$('#new_book_price_discount').text((((parseFloat(data.new_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#good_book_price_discount').text((((parseFloat(data.good_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#medium_book_price_discount').text((((parseFloat(data.medium_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#recyle_price_discount').text((((parseFloat(data.recyle_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#old_price').keyup(function() {
							v1 = $(this).val();
						});
						$('#new_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#new_book_discount').text('0');
					            	} else {
					            		$('#new_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#good_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#good_book_discount').text('0');
					            	} else {
					            		$('#good_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount').text('0');
					            	} else {
					            		$('#medium_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price2').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount2').text('0');
					            	} else {
					            		$('#medium_book_discount2').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price3').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount3').text('0');
					            	} else {
					            		$('#medium_book_discount3').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price4').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount4').text('0');
					            	} else {
					            		$('#medium_book_discount4').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price5').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount5').text('0');
					            	} else {
					            		$('#medium_book_discount5').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price6').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount6').text('0');
					            	} else {
					            		$('#medium_book_discount6').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
						$('#recyle_price').keyup(function() {
							v2 = $(this).val();
							if(v1 == '') { //验证第一个是否输入
								//alert('第一个文本框不为空');
								return false;
							} else {
								if(v2 == '') {
									//alert('第二个文本框不为空');
								} else {
									if(parseFloat(v2) / parseFloat(v1) == 1) {
										$('#recyle_price_discount').text('0');
									} else {
										$('#recyle_price_discount').text((((parseFloat(v2) / parseFloat(v1)) * 10)).toFixed(1));
									}

								}
							}
						});
						// 获取二级分类
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.category_pid,
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
								var _html1 = '';
								for(var i = 0; i < data.data.length; i++) {
									if(parseInt(data.data[i].id) !==0) {
									    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
									}
								}
								$("#first-category-ids").append(_html1);
								for(var i = 0; i < flavors.length; i++) {
									$("input[name='category_ids']").each(function() {
										if($(this).val() == flavors[i]) {
											$(this).attr("checked", "checked");
										}
									})
								}
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						// 检测ISBN
						$('#detection').on('click', function() {
							//执行 Ajax 后重载
							$.ajax({
								type: "POST",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/book/check_isbn",
								data: {
									isbn: $('#isbn').val()
								},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									console.log(data)
									if(data.message) {
										$('#msg_info').text('库中已存在')
										$("#msg_info").css("color", "red");
									} else {
										$('#msg_info').text('库中不存在')
										$("#msg_info").css("color", "blue");
									}
								},
								error: function(msg) {
									console.log(msg)
								}
							});
							return false;
						});
						form.on('radio(category-pid)', function(data) {
							$("#first-category-ids").empty();
							// 获取二级分类
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.value,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									var _html1 = '';
									for(var i = 0; i < data.data.length; i++) {
										if(parseInt(data.data[i].id) !==0) {
										    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
										}
									}
									$("#first-category-ids").append(_html1);
									form.render();
								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
						// 获取推荐位
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/homepage_recommend_module/index",
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
								var _html = '';
								for(var i = 0; i < data.data.length; i++) {
									_html += '<input type="checkbox" name="homepage_recommend_module_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
								}     
								$("#first-homepage-recommend-module-ids").append(_html);
								for(var i = 0; i < omg.length; i++) {
									$("input[name='homepage_recommend_module_ids']").each(function() {
										if($(this).val() == omg[i]) {
											$(this).attr("checked", "checked");
										}
									})
								}
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						form.on('radio(category-pid)', function(data) {
							$("#first-category-ids").empty();
							// 获取二级分类
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.value,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									var _html1 = '';
									for(var i = 0; i < data.data.length; i++) {
										if(parseInt(data.data[i].id) !==0) {
										    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
										}
									}
									$("#first-category-ids").append(_html1);
									form.render();
								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
						// 监听提交
						form.on('submit(layuiadmin-app-form-submit)', function(data) {
							var field = data.field; //获取提交的字段
							//提交 Ajax 成功后，关闭当前弹层并重载表格

							var arr = new Array();
							var arr_z = new Array();   
							$("input:checkbox[name='category_ids']:checked").each(function(i) {     
								arr[i] = $(this).val();  
							});
							$("input:checkbox[name='homepage_recommend_module_ids']:checked").each(function(s) {     
								arr_z[s] = $(this).val();  
							});   
							data.field.category_ids = arr.join(","); //将数组合并成字符串
							data.field.homepage_recommend_module_ids = arr_z.join(","); //将数组合并成字符串
							//执行 Ajax 后重载
							$.ajax({
								type: "PUT",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/book/update",
								data: {
									id: data.field.id,
									'category_pid': data.field.category_pid,
									'category_ids': data.field.category_ids,
									'title': data.field.title,
									'author': data.field.author,
									'sub_title': data.field.sub_title,
									'score': data.field.score,
									'image': data.field.image,
									'author_intro': content_author_intro,
									'publish_house': data.field.publish_house,
									'publish_time': data.field.publish_time,
									'publish_num': data.field.publish_num,
									'publish_translator': data.field.publish_translator,
									'publish_package': data.field.publish_package,
									'publish_paper': data.field.publish_paper,
									'publish_pages': data.field.publish_pages,
									'publish_open': data.field.publish_open,
									'isbn': data.field.isbn,
									'desc': content_desc,
									'catalog': content_catalog,
									'old_price': data.field.old_price,
									'new_book_price': data.field.new_book_price,
									'new_book_stock': data.field.new_book_stock,
									'good_book_price': data.field.good_book_price,
									'good_book_stock': data.field.good_book_stock,
									'medium_book_price': data.field.medium_book_price,
									'medium_book_stock': data.field.medium_book_stock,
									'medium_book_price2':data.field.medium_book_price2,
									'medium_book_stock2':data.field.medium_book_stock2,
									'medium_book_price3':data.field.medium_book_price3,
									'medium_book_stock3':data.field.medium_book_stock3,
									'medium_book_price4':data.field.medium_book_price4,
									'medium_book_stock4':data.field.medium_book_stock4,
									'medium_book_price5':data.field.medium_book_price5,
									'medium_book_stock5':data.field.medium_book_stock5,
									'medium_book_price6':data.field.medium_book_price6,
									'medium_book_stock6':data.field.medium_book_stock6,
									'is_recycle': data.field.is_recycle,
									'is_sult': data.field.is_sult,
									'recyle_price': data.field.recyle_price,
									'homepage_recommend_module_ids': data.field.homepage_recommend_module_ids
								},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									if(data.code == 0) {
										layer.msg('操作成功');
										layui.table.reload('LAY-good-list-status1');
										layui.table.reload('LAY-good-list-status2');
										layui.table.reload('LAY-good-list-status3');
										layui.table.reload('LAY-good-list-status4');
										layui.table.reload('LAY-good-list-status5');
					                    layui.table.reload('LAY-good-list-status6');
										// 执行关闭
										layer.close(index);
									} else {
										layer.msg(data.message);
									}

								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
					});
				}
			});
		} else if(obj.event === 'tips1') {
			admin.popup({
				title: '查看',
				area: ['400px', '350px'],
				id: 'LAY-popup-content-edit',
				success: function(layero, index) {
					view(this.id).render('goods/goods-list/price', data).done(function() {
						form.render(null, 'layuiadmin-form-tags1');
					});
				}
			});
		} else if(obj.event === 'tips2') {
			admin.popup({
				title: '查看',
				area: ['400px', '350px'],
				id: 'LAY-popup-content-edit1',
				success: function(layero, index) {
					view(this.id).render('goods/goods-list/stock', data).done(function() {
						form.render(null, 'layuiadmin-form-tags2');
					});
				}
			});
		} else if (obj.event === 'comment') {
		      admin.popup({
		        title: '编辑评论'
		        ,area: ['80%', '80%']
		        ,id: 'LAY-popup-comment-edit'
		        ,success: function(layero, index){
		          view(this.id).render('goods/goods-list/comment', data).done(function(){
		            form.render(null, 'layuiadmin-comment-list');
		            var book_id = data.id;
				    var cols = [[
				             {field:'user_avatar', title: '用户头像',templet: '#LAY-good-list-table-stock19',width:120,align: 'center'},
				             {field:'user_nickname', title: '用户'}
				            ,{field:'content', title: '评价内容'}
				            ,{field:'score', title: '评分'}
				            ,{width:178, align:'center', fixed: 'right',title: '操作', toolbar: '#LAY-good-list-table-edit1'}
				          ]];
					  table.set({
					    headers: { //通过 request 头传递
					      'access-token': layui.data('layuiAdmin').access_token
					    }
					  });
					  // 删除评论
					  table.on('tool(LAY-good-comment)', function(obj){
					  	var data = obj.data;
					  	if(obj.event === 'del'){
				        layer.confirm('是否删除', function(index){
				   	    $.ajax({
							    type: "DELETE",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/destroy",
							    data: {id:data.id},
							    headers: { //通过 request 头传递
					              'access-token': layui.data('layuiAdmin').access_token
					            },
								success: function(data){
								    layer.msg('操作成功');
								    layui.table.reload('LAY-good-comment'); //重载表格
						        layer.close(index); //执行关闭
								},
								error: function(msg){
								  console.log(msg)
								}
							});
				        });
					  	}
					  })
				    table.render({
				      elem: '#LAY-good-comment'
				      ,url: 'https://bookshop.dingdangtoy.com/api/admin/book_comment/index?book_id='+book_id
				      ,parseData: function(res){ //res 即为原始返回的数据
				        return {
				          "code": res.code, //解析接口状态
				          "msg": res.message, //解析提示文本
				          "data": res.data.items //解析数据列表
				        }
				      }
				      ,cols: cols
				      ,page: false
				    });
				    // 获取 图书信息
				    $.ajax({
						    type: "GET",
						    dataType: "json",
						    url: "https://bookshop.dingdangtoy.com/api/admin/book/show?id="+ book_id,
						    data: {},
						    headers: { //通过 request 头传递
					          'access-token': layui.data('layuiAdmin').access_token
					        },
							success: function(data){
								console.log(data.data)
								$('#title').text(data.data.title)
								$('#author').text(data.data.author)
								$('#title').text(data.data.title)
								$('#ISBN').text(data.data.isbn)
								$('#image').attr('src',data.data.image)
								form.render();
							},
							error: function(msg){
							  console.log(msg)
							}
						});
				    form.render(null, 'add-goods-form')
				    //监听提交
				    form.on('submit(formDemo)', function(data){
				    console.log(data)
				    layer.confirm('是否执行此操作？', function(index) {
				          //执行 Ajax 后重载
						    $.ajax({
							    type: "POST",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/store",
							    data: {
							    	book_id: book_id,
							    	user_nickname: data.field.user_nickname,
							    	user_id: data.field.user_id,
							    	user_avatar: data.field.user_avatar,
							    	score: data.field.score,
							    	content: data.field.content
							    },
							    headers: { //通过 request 头传递
						          'access-token': layui.data('layuiAdmin').access_token
						        },
								success: function(data){

				          table.reload('LAY-good-comment');
				          layer.msg('操作成功');
								},
								error: function(msg){
								  console.log(msg)
								}
							});
				        });
				    return false;
				    });
				    // 随机姓名
				    $('#random').on('click', function(){
				          //执行 Ajax 后重载
						    $.ajax({
							    type: "GET",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/user/rand_one",
							    data: {},
							    headers: { //通过 request 头传递
						          'access-token': layui.data('layuiAdmin').access_token
						        },
								success: function(data){
									$('#user_nickname').val(data.data.nickname);
									$('#user_id').val(data.data.user_id);
							        $('#avatar1').val(data.data.avatar);
						            $('#avatar').attr('src',data.data.avatar)
								},
								error: function(msg){
								  console.log(msg)
								}
							});
							return false;
				  });
		          });
		        }
		      });
		}
	});
	table.on('tool(LAY-good-list-status3)', function(obj) {
		var data = obj.data;
		if(obj.event === 'down') {
			$.ajax({
				type: "PUT",
				dataType: "json",
				url: "https://bookshop.dingdangtoy.com/api/admin/book/update_state",
				data: {
					state: '2',
					id: data.id
				},
				headers: { //通过 request 头传递
					'access-token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					layer.msg('操作成功');
					layui.table.reload('LAY-good-list-status1');
					layui.table.reload('LAY-good-list-status2');
					layui.table.reload('LAY-good-list-status3');
					layui.table.reload('LAY-good-list-status4');
					layui.table.reload('LAY-good-list-status5');
					layui.table.reload('LAY-good-list-status6');
				},
				error: function(msg) {
					console.log(msg)
				}
			});
		} else if(obj.event === 'up') {
			$.ajax({
				type: "PUT",
				dataType: "json",
				url: "https://bookshop.dingdangtoy.com/api/admin/book/update_state",
				data: {
					state: '1',
					id: data.id
				},
				headers: { //通过 request 头传递
					'access-token': layui.data('layuiAdmin').access_token
				},
				success: function(data) {
					layer.msg('操作成功');
					layui.table.reload('LAY-good-list-status1');
					layui.table.reload('LAY-good-list-status2');
					layui.table.reload('LAY-good-list-status3');
					layui.table.reload('LAY-good-list-status4');
					layui.table.reload('LAY-good-list-status5');
					layui.table.reload('LAY-good-list-status6');
				},
				error: function(msg) {
					console.log(msg)
				}
			});
		} else if(obj.event === 'del') {
			layer.confirm('是否删除', function(index) {
				//        obj.del();
				//        layer.close(index);
				$.ajax({
					type: "DELETE",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/destroy",
					data: {
						id: data.id
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layer.msg('操作成功');
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.close(index); //执行关闭
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		} else if(obj.event === 'edit') {
			//         location.hash = '/goods/add-goods/index/book_id='+data.id;
			admin.popup({
				title: '编辑书籍',
				area: ['90%', '90%'],
				id: 'LAY-popup-shopping-add',
				success: function(layero, index) {
					view(this.id).render('goods/add-goods/addShopping', data).done(function() {
						form.render(null, 'layuiadmin-app-form-list');
						var content_author_intro = '';
						var content_desc = '';
						var content_catalog = '';
						// 富文本
				        var E = window.wangEditor
				        var editor2 = new E('#editor2')
				        editor2.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
				            content_catalog = html
				        }
						editor2.create()
				        var editor1 = new E('#editor1')
				        editor1.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
				            content_desc = html
				        }
						editor1.create()
				        var editor = new E('#editor')
				        editor.customConfig.onchange = function (html) {
				            // 监控变化，同步更新到 textarea
                           content_author_intro = html
				        }
						editor.create()
						function toDecimal(num, n) {
							n = n ? parseInt(n) : 0;
							if(n <= 0) {
								return Math.round(num);
							}
							num = Math.round(num * Math.pow(10, n)) / Math.pow(10, n); //四舍五入
							num = Number(num).toFixed(n); //补足位数
							return num;
						}
//						获取详情
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/book/show?id=" + data.id,
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
                                editor.txt.html(data.data.author_intro)
                                editor1.txt.html(data.data.desc)
                                editor2.txt.html(data.data.catalog)
                                content_desc = data.data.desc;
                                content_author_intro = data.data.author_intro;
								content_catalog = data.data.catalog;
								$('#new_book_stock').val(data.data.new_book_stock);
								$('#good_book_stock').val(data.data.good_book_stock);
								$('#medium_book_stock').val(data.data.medium_book_stock);
								$('#medium_book_stock2').val(data.data.medium_book_stock2);
								$('#medium_book_stock3').val(data.data.medium_book_stock3);
								$('#medium_book_stock4').val(data.data.medium_book_stock4);
								$('#medium_book_stock5').val(data.data.medium_book_stock5);
								$('#medium_book_stock6').val(data.data.medium_book_stock6);

								$('#new_book_price').val(data.data.new_book_price);
								$('#good_book_price').val(data.data.good_book_price);
								$('#medium_book_price').val(data.data.medium_book_price);
								$('#medium_book_price2').val(data.data.medium_book_price2);
								$('#medium_book_price3').val(data.data.medium_book_price3);
								$('#medium_book_price4').val(data.data.medium_book_price4);
								$('#medium_book_price5').val(data.data.medium_book_price5);
								$('#medium_book_price6').val(data.data.medium_book_price6);

								var price1 = parseFloat(data.data.old_price);
								var price2 = parseFloat(data.data.new_book_price);
								var price3 = parseFloat(data.data.good_book_price);
								$('#new_book_discount').text(toDecimal((price2/price1)*10,1));
								$('#good_book_discount').text(toDecimal((price3/price1)*10,1));
								$('#medium_book_discount').text(toDecimal((parseFloat(data.data.medium_book_price)/price1)*10,1));
								$('#medium_book_discount2').text(toDecimal((parseFloat(data.data.medium_book_price2)/price1)*10,1));
								$('#medium_book_discount3').text(toDecimal((parseFloat(data.data.medium_book_price3)/price1)*10,1));
								$('#medium_book_discount4').text(toDecimal((parseFloat(data.data.medium_book_price4)/price1)*10,1));
								$('#medium_book_discount5').text(toDecimal((parseFloat(data.data.medium_book_price5)/price1)*10,1));
								$('#medium_book_discount6').text(toDecimal((parseFloat(data.data.medium_book_price6)/price1)*10,1));
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						// 计算总价
						$('#allPrice').on('click', function(){
							var price1 = parseFloat($('#old_price').val());
							var price2 = parseFloat($('#new_book_price').val());
							var price3 = parseFloat($('#good_book_price').val());
							var pax = price3 + (price1*0.13);
		                    $('#new_book_price').val(toDecimal(pax,1));
							$('#medium_book_price').val(toDecimal(price3*0.85,1));
							$('#medium_book_price2').val(toDecimal(price3*0.75,1));
							$('#medium_book_price3').val(toDecimal(price3*0.7,1));
							$('#medium_book_price4').val(toDecimal(price3*0.8,1));
							$('#medium_book_price5').val(toDecimal(price3*0.75,1));
							$('#medium_book_price6').val(toDecimal(price3*0.7,1));
							$('#new_book_discount').text(toDecimal((parseFloat($('#new_book_price').val())/price1)*10,1));
							$('#good_book_discount').text(toDecimal((price3/price1)*10,1));
							$('#medium_book_discount').text(toDecimal((parseFloat($('#medium_book_price').val())/price1)*10,1));
							$('#medium_book_discount2').text(toDecimal((parseFloat($('#medium_book_price2').val())/price1)*10,1));
							$('#medium_book_discount3').text(toDecimal((parseFloat($('#medium_book_price3').val())/price1)*10,1));
							$('#medium_book_discount4').text(toDecimal((parseFloat($('#medium_book_price4').val())/price1)*10,1));
							$('#medium_book_discount5').text(toDecimal((parseFloat($('#medium_book_price5').val())/price1)*10,1));
							$('#medium_book_discount6').text(toDecimal((parseFloat($('#medium_book_price6').val())/price1)*10,1));
							return false;
						});
						//上传图片
						upload.render({
							elem: '#add-goods-upload-btn',
							url: 'https://bookshop.dingdangtoy.com/api/admin/image/store',
							accept: 'images',
							method: 'get',
							acceptMime: 'image/*',
							done: function(res) {
								console.log(res.data.url)
								$('#add-goods-upload-img').attr('src', res.data.url);
								$('#add-goods-upload-image').val(res.data.url)
								//$(this.item).prev("div").children("input").val(res.data.url)
							}
						});
						var flavors = data.category_ids.split(",");
						var v1 = '';
						var v2 = '';
						// 推荐位
						var omg = data.homepage_recommend_module_ids.split(",");
						if(data.old_price) {
							v1 = data.old_price;
						}
						$('#new_book_price_discount').text((((parseFloat(data.new_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#good_book_price_discount').text((((parseFloat(data.good_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#medium_book_price_discount').text((((parseFloat(data.medium_book_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#recyle_price_discount').text((((parseFloat(data.recyle_price) / parseFloat(data.old_price)) * 10)).toFixed(1));
						$('#old_price').keyup(function() {
							v1 = $(this).val();
						});
						$('#new_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#new_book_discount').text('0');
					            	} else {
					            		$('#new_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#good_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#good_book_discount').text('0');
					            	} else {
					            		$('#good_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount').text('0');
					            	} else {
					            		$('#medium_book_discount').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price2').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount2').text('0');
					            	} else {
					            		$('#medium_book_discount2').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price3').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount3').text('0');
					            	} else {
					            		$('#medium_book_discount3').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price4').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount4').text('0');
					            	} else {
					            		$('#medium_book_discount4').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price5').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount5').text('0');
					            	} else {
					            		$('#medium_book_discount5').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
					    $('#medium_book_price6').keyup(function(){
					        v2 = $(this).val();
					        if(v1 == ''){//验证第一个是否输入
					            //alert('第一个文本框不为空');
					            return false;
					        }else{
					            if(v2 == ''){
					                //alert('第二个文本框不为空');
					            }else{
					            	if(parseFloat(v2)/parseFloat(v1) == 1) {
					            		$('#medium_book_discount6').text('0');
					            	} else {
					            		$('#medium_book_discount6').text(toDecimal((parseFloat(v2)/parseFloat(v1))*10,1));
					            	}

					            }
					        }
					    });
						$('#recyle_price').keyup(function() {
							v2 = $(this).val();
							if(v1 == '') { //验证第一个是否输入
								//alert('第一个文本框不为空');
								return false;
							} else {
								if(v2 == '') {
									//alert('第二个文本框不为空');
								} else {
									if(parseFloat(v2) / parseFloat(v1) == 1) {
										$('#recyle_price_discount').text('0');
									} else {
										$('#recyle_price_discount').text((((parseFloat(v2) / parseFloat(v1)) * 10)).toFixed(1));
									}

								}
							}
						});
						// 获取二级分类
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.category_pid,
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
								var _html1 = '';
								for(var i = 0; i < data.data.length; i++) {
									if(parseInt(data.data[i].id) !==0) {
									    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
									}
								}
								$("#first-category-ids").append(_html1);
								for(var i = 0; i < flavors.length; i++) {
									$("input[name='category_ids']").each(function() {
										if($(this).val() == flavors[i]) {
											$(this).attr("checked", "checked");
										}
									})
								}
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						// 检测ISBN
						$('#detection').on('click', function() {
							//执行 Ajax 后重载
							$.ajax({
								type: "POST",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/book/check_isbn",
								data: {
									isbn: $('#isbn').val()
								},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									console.log(data)
									if(data.message) {
										$('#msg_info').text('库中已存在')
										$("#msg_info").css("color", "red");
									} else {
										$('#msg_info').text('库中不存在')
										$("#msg_info").css("color", "blue");
									}
								},
								error: function(msg) {
									console.log(msg)
								}
							});
							return false;
						});
						form.on('radio(category-pid)', function(data) {
							$("#first-category-ids").empty();
							// 获取二级分类
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.value,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									var _html1 = '';
									for(var i = 0; i < data.data.length; i++) {
										if(parseInt(data.data[i].id) !==0) {
										    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
										}
									}
									$("#first-category-ids").append(_html1);
									form.render();
								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
						// 获取推荐位
						$.ajax({
							type: "GET",
							dataType: "json",
							url: "https://bookshop.dingdangtoy.com/api/admin/homepage_recommend_module/index",
							data: {},
							headers: { //通过 request 头传递
								'access-token': layui.data('layuiAdmin').access_token
							},
							success: function(data) {
								var _html = '';
								for(var i = 0; i < data.data.length; i++) {
									_html += '<input type="checkbox" name="homepage_recommend_module_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
								}     
								$("#first-homepage-recommend-module-ids").append(_html);
								for(var i = 0; i < omg.length; i++) {
									$("input[name='homepage_recommend_module_ids']").each(function() {
										if($(this).val() == omg[i]) {
											$(this).attr("checked", "checked");
										}
									})
								}
								form.render();
							},
							error: function(msg) {
								console.log(msg)
							}
						});
						form.on('radio(category-pid)', function(data) {
							$("#first-category-ids").empty();
							// 获取二级分类
							$.ajax({
								type: "GET",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid=" + data.value,
								data: {},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									var _html1 = '';
									for(var i = 0; i < data.data.length; i++) {
										if(parseInt(data.data[i].id) !==0) {
										    _html1 += '<input type="checkbox" name="category_ids" value="' + data.data[i].id + '" title="' + data.data[i].title + '">'
										}
									}
									$("#first-category-ids").append(_html1);
									form.render();
								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
						// 监听提交
						form.on('submit(layuiadmin-app-form-submit)', function(data) {
							var field = data.field; //获取提交的字段
							//提交 Ajax 成功后，关闭当前弹层并重载表格

							var arr = new Array();
							var arr_z = new Array();   
							$("input:checkbox[name='category_ids']:checked").each(function(i) {     
								arr[i] = $(this).val();  
							});
							$("input:checkbox[name='homepage_recommend_module_ids']:checked").each(function(s) {     
								arr_z[s] = $(this).val();  
							});   
							data.field.category_ids = arr.join(","); //将数组合并成字符串
							data.field.homepage_recommend_module_ids = arr_z.join(","); //将数组合并成字符串
							//执行 Ajax 后重载
							$.ajax({
								type: "PUT",
								dataType: "json",
								url: "https://bookshop.dingdangtoy.com/api/admin/book/update",
								data: {
									id: data.field.id,
									'category_pid': data.field.category_pid,
									'category_ids': data.field.category_ids,
									'title': data.field.title,
									'author': data.field.author,
									'sub_title': data.field.sub_title,
									'score': data.field.score,
									'image': data.field.image,
									'author_intro': content_author_intro,
									'publish_house': data.field.publish_house,
									'publish_time': data.field.publish_time,
									'publish_num': data.field.publish_num,
									'publish_translator': data.field.publish_translator,
									'publish_package': data.field.publish_package,
									'publish_paper': data.field.publish_paper,
									'publish_pages': data.field.publish_pages,
									'publish_open': data.field.publish_open,
									'isbn': data.field.isbn,
									'desc': content_desc,
									'catalog': content_catalog,
									'old_price': data.field.old_price,
									'new_book_price': data.field.new_book_price,
									'new_book_stock': data.field.new_book_stock,
									'good_book_price': data.field.good_book_price,
									'good_book_stock': data.field.good_book_stock,
									'medium_book_price': data.field.medium_book_price,
									'medium_book_stock': data.field.medium_book_stock,
									'medium_book_price2':data.field.medium_book_price2,
									'medium_book_stock2':data.field.medium_book_stock2,
									'medium_book_price3':data.field.medium_book_price3,
									'medium_book_stock3':data.field.medium_book_stock3,
									'medium_book_price4':data.field.medium_book_price4,
									'medium_book_stock4':data.field.medium_book_stock4,
									'medium_book_price5':data.field.medium_book_price5,
									'medium_book_stock5':data.field.medium_book_stock5,
									'medium_book_price6':data.field.medium_book_price6,
									'medium_book_stock6':data.field.medium_book_stock6,
									'is_recycle': data.field.is_recycle,
									'is_sult': data.field.is_sult,
									'recyle_price': data.field.recyle_price,
									'homepage_recommend_module_ids': data.field.homepage_recommend_module_ids
								},
								headers: { //通过 request 头传递
									'access-token': layui.data('layuiAdmin').access_token
								},
								success: function(data) {
									if(data.code == 0) {
										layer.msg('操作成功');
										layui.table.reload('LAY-good-list-status1');
										layui.table.reload('LAY-good-list-status2');
										layui.table.reload('LAY-good-list-status3');
										layui.table.reload('LAY-good-list-status4');
										layui.table.reload('LAY-good-list-status5');
					                    layui.table.reload('LAY-good-list-status6');
										// 执行关闭
										layer.close(index);
									} else {
										layer.msg(data.message);
									}

								},
								error: function(msg) {
									console.log(msg)
								}
							});
						});
					});
				}
			});
		} else if(obj.event === 'tips1') {
			admin.popup({
				title: '查看',
				area: ['400px', '350px'],
				id: 'LAY-popup-content-edit',
				success: function(layero, index) {
					view(this.id).render('goods/goods-list/price', data).done(function() {
						form.render(null, 'layuiadmin-form-tags1');
					});
				}
			});
		} else if(obj.event === 'tips2') {
			admin.popup({
				title: '查看',
				area: ['400px', '350px'],
				id: 'LAY-popup-content-edit1',
				success: function(layero, index) {
					view(this.id).render('goods/goods-list/stock', data).done(function() {
						form.render(null, 'layuiadmin-form-tags2');
					});
				}
			});
		} else if (obj.event === 'comment') {
		      admin.popup({
		        title: '编辑评论'
		        ,area: ['80%', '80%']
		        ,id: 'LAY-popup-comment-edit'
		        ,success: function(layero, index){
		          view(this.id).render('goods/goods-list/comment', data).done(function(){
		            form.render(null, 'layuiadmin-comment-list');
		            var book_id = data.id;
				    var cols = [[
				            {field:'user_avatar', title: '用户头像',templet: '#LAY-good-list-table-stock19',width:120,align: 'center'}
				            ,{field:'user_nickname', title: '用户'}
				            ,{field:'content', title: '评价内容'}
				            ,{field:'score', title: '评分'}
				            ,{width:178, align:'center', fixed: 'right',title: '操作', toolbar: '#LAY-good-list-table-edit1'}
				          ]];
					  table.set({
					    headers: { //通过 request 头传递
					      'access-token': layui.data('layuiAdmin').access_token
					    }
					  });
					  // 删除评论
					  table.on('tool(LAY-good-comment)', function(obj){
					  	var data = obj.data;
					  	if(obj.event === 'del'){
				        layer.confirm('是否删除', function(index){
				   	    $.ajax({
							    type: "DELETE",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/destroy",
							    data: {id:data.id},
							    headers: { //通过 request 头传递
					              'access-token': layui.data('layuiAdmin').access_token
					            },
								success: function(data){
								    layer.msg('操作成功');
								    layui.table.reload('LAY-good-comment'); //重载表格
						        layer.close(index); //执行关闭
								},
								error: function(msg){
								  console.log(msg)
								}
							});
				        });
					  	}
					  })
				    table.render({
				      elem: '#LAY-good-comment'
				      ,url: 'https://bookshop.dingdangtoy.com/api/admin/book_comment/index?book_id='+book_id
				      ,parseData: function(res){ //res 即为原始返回的数据
				        return {
				          "code": res.code, //解析接口状态
				          "msg": res.message, //解析提示文本
				          "data": res.data.items //解析数据列表
				        }
				      }
				      ,cols: cols
				      ,page: false
				    });
				    // 获取 图书信息
				    $.ajax({
						    type: "GET",
						    dataType: "json",
						    url: "https://bookshop.dingdangtoy.com/api/admin/book/show?id="+ book_id,
						    data: {},
						    headers: { //通过 request 头传递
					          'access-token': layui.data('layuiAdmin').access_token
					        },
							success: function(data){
								console.log(data.data)
								$('#title').text(data.data.title)
								$('#author').text(data.data.author)
								$('#title').text(data.data.title)
								$('#ISBN').text(data.data.isbn)
								$('#image').attr('src',data.data.image)
								form.render();
							},
							error: function(msg){
							  console.log(msg)
							}
						});
				    form.render(null, 'add-goods-form')
				    //监听提交
				    form.on('submit(formDemo)', function(data){
				    console.log(data)
				    layer.confirm('是否执行此操作？', function(index) {
				          //执行 Ajax 后重载
						    $.ajax({
							    type: "POST",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/book_comment/store",
							    data: {
							    	book_id: book_id,
							    	user_nickname: data.field.user_nickname,
							    	user_id: data.field.user_id,
							    	user_avatar: data.field.user_avatar,
							    	score: data.field.score,
							    	content: data.field.content
							    },
							    headers: { //通过 request 头传递
						          'access-token': layui.data('layuiAdmin').access_token
						        },
								success: function(data){

				          table.reload('LAY-good-comment');
				          layer.msg('操作成功');
								},
								error: function(msg){
								  console.log(msg)
								}
							});
				        });
				    return false;
				    });
				    // 随机姓名
				    $('#random').on('click', function(){
				          //执行 Ajax 后重载
						    $.ajax({
							    type: "GET",
							    dataType: "json",
							    url: "https://bookshop.dingdangtoy.com/api/admin/user/rand_one",
							    data: {},
							    headers: { //通过 request 头传递
						          'access-token': layui.data('layuiAdmin').access_token
						        },
								success: function(data){
									$('#user_nickname').val(data.data.nickname);
									$('#user_id').val(data.data.user_id);
						            $('#avatar1').val(data.data.avatar);
					                $('#avatar').attr('src',data.data.avatar)
								},
								error: function(msg){
								  console.log(msg)
								}
							});
							return false;
				  });
		          });
		        }
		      });
		}
	});
	// 获取 推荐位
	$.ajax({
		type: "GET",
		dataType: "json",
		url: "https://bookshop.dingdangtoy.com/api/admin/homepage_recommend_module/index",
		data: {},
		headers: { //通过 request 头传递
			'access-token': layui.data('layuiAdmin').access_token
		},
		success: function(data) {
			var _html = '';
			for(var i = 0; i < data.data.length; i++) {
				_html += '<option value="' + data.data[i].id + '">' + data.data[i].title + '</option>'
			}     
			$("#homepage_recommend_module_id").append(_html);
			form.render();
		},
		error: function(msg) {
			console.log(msg)
		}
	});
	// 获取 分类
	$.ajax({
		type: "GET",
		dataType: "json",
		url: "https://bookshop.dingdangtoy.com/api/admin/category/parent_list",
		data: {},
		headers: { //通过 request 头传递
			'access-token': layui.data('layuiAdmin').access_token
		},
		success: function(data) {
			var _html = '';
			for(var i = 0; i < data.data.length; i++) {
				_html += '<option value="' + data.data[i].id + '">' + data.data[i].title + '</option>'
			}     
			$("#category_pid").append(_html);
			form.render();
		},
		error: function(msg) {
			console.log(msg)
		}
	});
	form.on('select(category_pid)', function(data){
		$("#first-category-ids1").empty();
		  // 获取二级分类
	    $.ajax({
			    type: "GET",
			    dataType: "json",
			    url: "https://bookshop.dingdangtoy.com/api/admin/category/list?pid="+data.value,
			    data: {},
			    headers: { //通过 request 头传递
		          'access-token': layui.data('layuiAdmin').access_token
		        },
				success: function(data){
					var _html1 = '';
					for(var i = 0; i < data.data.length; i++) {
						_html1 += '<option value="' + data.data[i].id + '">' + data.data[i].title + '</option>'
					}
		      $("#first-category-ids1").append(_html1);
					form.render();
				},
				error: function(msg){
				  console.log(msg)
				}
			});
		});
	form.on('submit(goods-list-search1)', function(data) {

		$("#keyword").val('');

		var num1 = '';
		switch(parseFloat(curr_tab)) {
			case 0:
				table.reload('LAY-good-list-status1', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'category_pid': num1,
						'first-category-ids': num1,
						'homepage_recommend_module_id': num1,
						'is_recycle': num1,
						'keyword': num1
					}
				});
				break;
			case 1:
				table.reload('LAY-good-list-status2', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'category_pid': num1,
						'first-category-ids': num1,
						'homepage_recommend_module_id': num1,
						'is_recycle': num1,
						'keyword': num1
					}
				});
				break;
			case 2:
				table.reload('LAY-good-list-status3', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'category_pid': num1,
						'first-category-ids': num1,
						'homepage_recommend_module_id': num1,
						'is_recycle': num1,
						'keyword': num1
					}
				});
				break;
				case 3:
				table.reload('LAY-good-list-status5', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'category_pid': num1,
						'first-category-ids': num1,
						'homepage_recommend_module_id': num1,
						'is_recycle': num1,
						'keyword': num1
					}
				});
				break;
				case 4:
				table.reload('LAY-good-list-status6', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'category_pid': num1,
						'first-category-ids': num1,
						'homepage_recommend_module_id': num1,
						'is_recycle': num1,
						'keyword': num1
					}
				});
				break;
				case 5:
				table.reload('LAY-good-list-status4', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'category_pid': num1,
						'first-category-ids': num1,
						'homepage_recommend_module_id': num1,
						'is_recycle': num1,
						'keyword': num1
					}
				});
				break;
		}
		return false;
	});
	// 搜索 ,

	form.on('submit(goods-list-search)', function(data) {
		switch(parseFloat(curr_tab)) {
			case 0:
				table.reload('LAY-good-list-status1', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'category_pid': $('#category_pid option:selected').val(),
						'total_stock_sort': $('#total_stock_sort option:selected').val(),
						'sales_total_sort': $('#sales_total_sort option:selected').val(),
						'first-category-ids': $('#first-category-ids1 option:selected').val(),
						'homepage_recommend_module_id': $('#homepage_recommend_module_id option:selected').val(),
						'is_recycle': $('#is_recycle option:selected').val(),
						'keyword': $('#keyword').val()
					}
				});
				break;
			case 1:
				table.reload('LAY-good-list-status2', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'category_pid': $('#category_pid option:selected').val(),
						'total_stock_sort': $('#total_stock_sort option:selected').val(),
						'sales_total_sort': $('#sales_total_sort option:selected').val(),
						'first-category-ids': $('#first-category-ids1 option:selected').val(),
						'homepage_recommend_module_id': $('#homepage_recommend_module_id option:selected').val(),
						'is_recycle': $('#is_recycle option:selected').val(),
						'keyword': $('#keyword').val()
					}
				});
				break;
			case 2:
				table.reload('LAY-good-list-status3', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'category_pid': $('#category_pid option:selected').val(),
						'total_stock_sort': $('#total_stock_sort option:selected').val(),
						'sales_total_sort': $('#sales_total_sort option:selected').val(),
						'first-category-ids': $('#first-category-ids1 option:selected').val(),
						'homepage_recommend_module_id': $('#homepage_recommend_module_id option:selected').val(),
						'is_recycle': $('#is_recycle option:selected').val(),
						'keyword': $('#keyword').val()
					}
				});
				break;
				case 3:
				table.reload('LAY-good-list-status5', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'category_pid': $('#category_pid option:selected').val(),
						'total_stock_sort': $('#total_stock_sort option:selected').val(),
						'sales_total_sort': $('#sales_total_sort option:selected').val(),
						'first-category-ids': $('#first-category-ids1 option:selected').val(),
						'homepage_recommend_module_id': $('#homepage_recommend_module_id option:selected').val(),
						'is_recycle': $('#is_recycle option:selected').val(),
						'keyword': $('#keyword').val()
					}
				});
				break;
				case 4:
				table.reload('LAY-good-list-status6', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'category_pid': $('#category_pid option:selected').val(),
						'total_stock_sort': $('#total_stock_sort option:selected').val(),
						'sales_total_sort': $('#sales_total_sort option:selected').val(),
						'first-category-ids': $('#first-category-ids1 option:selected').val(),
						'homepage_recommend_module_id': $('#homepage_recommend_module_id option:selected').val(),
						'is_recycle': $('#is_recycle option:selected').val(),
						'keyword': $('#keyword').val()
					}
				});
				break;
				case 5:
				table.reload('LAY-good-list-status4', {
					page: {
						curr: 1 //重新从第 1 页开始
					},
					where: {
						'category_pid': $('#category_pid option:selected').val(),
						'total_stock_sort': $('#total_stock_sort option:selected').val(),
						'sales_total_sort': $('#sales_total_sort option:selected').val(),
						'first-category-ids': $('#first-category-ids1 option:selected').val(),
						'homepage_recommend_module_id': $('#homepage_recommend_module_id option:selected').val(),
						'is_recycle': $('#is_recycle option:selected').val(),
						'keyword': $('#keyword').val()
					}
				});
				break;
		}
		return false;
	});
	//事件
	var active = {
		batchdel: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status1');
			//得到选中的数据
			var checkData = checkStatus.data;

			if(checkData.length === 0) {
				console.log(checkData)
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: 1
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		batchdel1: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status2');
			//得到选中的数据
			var checkData = checkStatus.data;

			if(checkData.length === 0) {
				console.log(checkData)
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: 1
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {

						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
				    	layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		batchdel2: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status3');
			//得到选中的数据
			var checkData = checkStatus.data;

			if(checkData.length === 0) {
				console.log(checkData)
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: 1
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {

						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
				    	layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		batchdel3: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status4');
			//得到选中的数据
			var checkData = checkStatus.data;

			if(checkData.length === 0) {
				console.log(checkData)
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: 1
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		batchdel5: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status5');
			//得到选中的数据
			var checkData = checkStatus.data;

			if(checkData.length === 0) {
				console.log(checkData)
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: 1
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		batchdel6: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status6');
			//得到选中的数据
			var checkData = checkStatus.data;

			if(checkData.length === 0) {
				console.log(checkData)
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: 1
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},

		support: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status1'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '2',
						is_recycle: '1'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		support1: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status2'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '2',
						is_recycle: '1'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
				    	layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		support2: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status3'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '2',
						is_recycle: '1'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
				    	layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		support3: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status4'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '2',
						is_recycle: '1'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
				    	layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		support5: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status5'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '2',
						is_recycle: '1'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
				    	layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		support6: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status6'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '2',
						is_recycle: '1'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
				    	layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},

		noSupport: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status1'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '3',
						is_recycle: '2'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		noSupport1: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status2'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '3',
						is_recycle: '2'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		noSupport2: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status3'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '3',
						is_recycle: '2'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
				    	layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		noSupport3: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status4'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '3',
						is_recycle: '2'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		noSupport5: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status5'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '3',
						is_recycle: '2'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		noSupport6: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status6'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '3',
						is_recycle: '2'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						layui.table.reload('LAY-good-list-status1');
						layui.table.reload('LAY-good-list-status2');
						layui.table.reload('LAY-good-list-status3');
						layui.table.reload('LAY-good-list-status4');
						layui.table.reload('LAY-good-list-status5');
					    layui.table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		allDown: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status1'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '5',
						state: '2'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						table.reload('LAY-good-list-status1');
						table.reload('LAY-good-list-status2');
						table.reload('LAY-good-list-status3');
						table.reload('LAY-good-list-status4');
						table.reload('LAY-good-list-status5');
					    table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		allDown1: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status2'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '5',
						state: '2'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						table.reload('LAY-good-list-status1');
						table.reload('LAY-good-list-status2');
						table.reload('LAY-good-list-status3');
						table.reload('LAY-good-list-status4');
						table.reload('LAY-good-list-status5');
					    table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		allDown2: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status3'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '5',
						state: '2'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						table.reload('LAY-good-list-status1');
						table.reload('LAY-good-list-status2');
						table.reload('LAY-good-list-status3');
						table.reload('LAY-good-list-status4');
						table.reload('LAY-good-list-status5');
					    table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		allDown3: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status4'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '5',
						state: '2'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						table.reload('LAY-good-list-status1');
						table.reload('LAY-good-list-status2');
						table.reload('LAY-good-list-status3');
						table.reload('LAY-good-list-status4');
						table.reload('LAY-good-list-status5');
					    table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		addUp: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status1'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '4',
						state: '1'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						table.reload('LAY-good-list-status1');
						table.reload('LAY-good-list-status2');
						table.reload('LAY-good-list-status3');
						table.reload('LAY-good-list-status4');
						table.reload('LAY-good-list-status5');
					    table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		addUp1: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status2'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '4',
						state: '1'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						table.reload('LAY-good-list-status1');
						table.reload('LAY-good-list-status2');
						table.reload('LAY-good-list-status3');
						table.reload('LAY-good-list-status4');
						table.reload('LAY-good-list-status5');
					    table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		addUp2: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status3'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '4',
						state: '1'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						table.reload('LAY-good-list-status1');
						table.reload('LAY-good-list-status2');
						table.reload('LAY-good-list-status3');
						table.reload('LAY-good-list-status4');
						table.reload('LAY-good-list-status5');
					    table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		addUp3: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status4'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '4',
						state: '1'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						table.reload('LAY-good-list-status1');
						table.reload('LAY-good-list-status2');
						table.reload('LAY-good-list-status3');
						table.reload('LAY-good-list-status4');
						table.reload('LAY-good-list-status5');
					    table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		addUp5: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status5'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '4',
						state: '1'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						table.reload('LAY-good-list-status1');
						table.reload('LAY-good-list-status2');
						table.reload('LAY-good-list-status3');
						table.reload('LAY-good-list-status4');
						table.reload('LAY-good-list-status5');
					    table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		},
		addUp6: function() {
			var checkStatus = table.checkStatus('LAY-good-list-status6'),
				checkData = checkStatus.data; //得到选中的数据

			if(checkData.length === 0) {
				return layer.msg('请选择数据');
			}
			var arr_1 = [];
			for(var i = 0; i < checkData.length; i++) {
				arr_1.push(checkData[i].id)
			}
			arr_1 = arr_1.join(',');
			layer.confirm('是否执行此操作？', function(index) {

				//执行 Ajax 后重载
				$.ajax({
					type: "POST",
					dataType: "json",
					url: "https://bookshop.dingdangtoy.com/api/admin/book/batch_action",
					data: {
						ids: arr_1,
						type: '4',
						state: '1'
					},
					headers: { //通过 request 头传递
						'access-token': layui.data('layuiAdmin').access_token
					},
					success: function(data) {
						table.reload('LAY-good-list-status1');
						table.reload('LAY-good-list-status2');
						table.reload('LAY-good-list-status3');
						table.reload('LAY-good-list-status4');
						table.reload('LAY-good-list-status5');
					    table.reload('LAY-good-list-status6');
						layer.msg('操作成功');
					},
					error: function(msg) {
						console.log(msg)
					}
				});
			});
		}
	};

	$('.layui-btn.layuiadmin-btn-useradmin').on('click', function() {
		var type = $(this).data('type');
		active[type] ? active[type].call(this) : '';
	});
	//对外暴露的接口
	exports('goods', {});
})
